![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: Howto: Add lines of text from a specific point in a text file.. "McKirahan" <News@xxxxxx> wrote in message news:eKudndy5JP_BfP3VnZ2dnUVZ_tDinZ2d@xxxxxx [snip] Quote: > Hopefully, your newreader kept the indentations that I had in the code. the indentations will be there and line-wrap will be more obvious. The script contains exactly 249 lines; from "<html>" thru "</html>". <html> <head> <title>SVCPack.hta</title> <HTA:Application ID = "HTA" ApplicationName = "SVCPack" Border = "thin" BorderStyle = "normal" Caption = "yes" ContextMenu="yes" Icon = "" InnerBorder="no" MaximizeButton = "yes" MinimizeButton = "yes" Navigable="yes" Scroll="yes" SrollFlat="no" Selection="yes" ShowInTaskBar = "yes" SingleInstance = "yes" SysMenu = "yes" Version = "1.0" WindowState = "maximize" Quote: > ~~~~Option Explicit '**** '*~~This HTA (HTML Application) does the following: '*~~1)~~Reads "cTXT" which contains a list of (path+) filenames '*~~~~~~and builds a dropdown list to allow selection. '*~~2)~~Reads the selected file into a textarea; '*~~~~~~(".inf" extensions builds a dropdown list of Sections). '*~~3)~~Changes may be made directly to the file or lines '*~~~~~~may entered in a textarea for inserting into multiple files. '*~~4)~~If the file has been changed then it may be saved which '*~~~~~~replaces the original file after it is "backed up" first by '*~~~~~~copying it with a timestamp extension: ".yyyymmddhhnnss". '**** ~~~'* ~~~'*~~Declare Constants ~~~'* ~~~~Const cHTA = "SVCPack.hta" ~~~~Const cTXT = "SVCPack.txt" ~~~'* ~~~'*~~Declare Globals ~~~'* ~~~~Dim sDIR ~~~~~~~~sDIR = CreateObject("WScript.Shell").CurrentDirectory + "\" ~~~~Dim sERR ~~~~Dim oFSO ~~~~Set oFSO = CreateObject("Scripting.FileSystemObject") ~~~~Dim sINF ~~~~Dim dNOW ~~~~Dim sNOW ' yyyymmddhhnnss ~~~~Dim aOTF ~~~~Dim iOTF ~~~~Dim oOTF ~~~~Dim sOTF ~~~~Dim iOPT ~~~~Dim sOPT ~~~~Dim sSAV ~~~~Dim sTMP Sub File_List() '**** '*~~Read file. '**** ~~~'* ~~~'*~~Test ~~~'* ~~~~If Not oFSO.FileExists(sDIR & cTXT) Then ~~~~~~~~sERR = "<b>" & cTXT & "</b> does not exist!" ~~~~~~~~document.getElementById("Note").innerHTML = sERR ~~~~~~~~Exit Sub ~~~~End If ~~~'* ~~~'*~~Read ~~~'* ~~~~Set oOTF = oFSO.OpenTextFile(sDIR & cTXT,1) ~~~~~~~~sOTF = oOTF.ReadAll ~~~~Set oOTF = Nothing ~~~'* ~~~'*~~List ~~~'* ~~~~~~~~iOPT = 1 ~~~~~~~~sOPT = "<option value=''>" & vbCrLf ~~~~~~~~aOTF = Split(sOTF,vbCrLf) ~~~~For iOTF = 0 To UBound(aOTF) ~~~~~~~~sOTF = Trim(aOTF(iOTF)) ~~~~~~~~If~~LCase(Left(sOTF,1)) >= "a" _ ~~~~~~~~And LCase(Left(sOTF,1)) <= "z" _ ~~~~~~~~And Mid(sOTF,2,2) = ":\" Then ~~~~~~~~~~~~If oFSO.FileExists(sOTF) Then ~~~~~~~~~~~~~~~~iOPT = iOPT + 1 ~~~~~~~~~~~~~~~~sOPT = sOPT & "<option value='" & sOTF & "'>" & sOTF & vbCrLf ~~~~~~~~~~~~Else ~~~~~~~~~~~~~~~~Alert(sOTF & " file does not exist!") ~~~~~~~~~~~~End If ~~~~~~~~End If ~~~~Next ~~~~sOPT = sOPT & "</select>" & vbCrLf ~~~~sOPT = "<select id='Pick1' onchange='File_Read()' size='" & iOPT & "'>" & sOPT & vbCrLf ~~~'* ~~~~document.getElementById("List").innerHTML = sOPT End Sub Sub File_Read() '**** '*~~Read file. '**** ~~~~document.getElementById("Note").innerHTML = "" ~~~~document.getElementById("Sect").innerHTML = "" ~~~~document.getElementById("Data").Value = "" ~~~~sINF = document.getElementById("Pick1").Value ~~~~If sINF = "" Then Exit Sub ~~~'* ~~~'*~~Test ~~~'* ~~~~If Not oFSO.FileExists(sINF) Then ~~~~~~~~sERR = "<b>" & sINF & "</b> does not exist!" ~~~~~~~~document.getElementById("Note").innerHTML = sERR ~~~~~~~~Exit Sub ~~~~End If ~~~'* ~~~'*~~Read ~~~'* ~~~~Set oOTF = oFSO.OpenTextFile(sINF,1) ~~~~~~~~sOTF = oOTF.ReadAll ~~~~Set oOTF = Nothing ~~~~document.getElementById("Data").Value = sOTF ~~~~sSAV = sOTF ~~~'* ~~~'*~~INF Sections ~~~'* ~~~~If Right(LCase(sINF),4) <> ".inf" Then Exit Sub ~~~~~~~~iOPT = 0 ~~~~~~~~sOPT = "" ~~~~~~~~aOTF = Split(sOTF,vbCrLf) ~~~~For iOTF = 0 To UBound(aOTF) ~~~~~~~~sOTF = Trim(aOTF(iOTF)) ~~~~~~~~If~~Left(sOTF,1) = "[" _ ~~~~~~~~And Right(sOTF,1) = "]" Then ~~~~~~~~~~~~ iOPT = iOPT + 1 ~~~~~~~~~~~~ sOPT = sOPT & "<option value='" & sOTF & "'>" & sOTF & vbCrLf ~~~~~~~~End If ~~~~Next ~~~'* ~~~~sOPT = sOPT & "</select>" & vbCrLf ~~~~sOPT = "<select size='" & iOPT & "'>" & sOPT & vbCrLf ~~~~sOPT = "<b>Sections:</b><br>" & vbCrLf & sOPT & vbCrLf ~~~~document.getElementById("Sect").innerHTML = sOPT End Sub Sub File_Position() '**** '*~~Inserting at the cursor using JavaScript '*~~http://alexking.org/blog/2003/06/02/...r-using-javasc ript/ '**** ~~~~sTMP = document.getElementById("Entry").Value ~~~~If sTMP = "" Then Exit Sub ~~~~If MsgBox("Insert text at cursor position?",vbQuestion+vbYesNo,cHTA) = vbYes Then ~~~~~~~~document.getElementById("Data").focus() ~~~~~~~~document.selection.createRange().text = sTMP ~~~~End If End Sub Sub File_Replace() '**** '*~~Copy old file and Write new file. '**** ~~~~dNOW = Now ~~~~sNOW = Year(dNOW) _ ~~~~~~~~~~~& (10^8 * Month(dNOW)) _ ~~~~~~~~~~~+ (10^6 * Day(dNOW)) _ ~~~~~~~~~~~+ (10^4 * Hour(dNOW)) _ ~~~~~~~~~~~+ (10^2 * Minute(dNOW)) _ ~~~~~~~~~~~+ (10^0 * Second(dNOW)) ~~~~sOTF = document.getElementById("Data").Value ~~~'* ~~~'*~~Test ~~~'* ~~~~If sINF = "" Then ~~~~~~~~sERR = "<b>No file selected!</b>" ~~~~~~~~document.getElementById("Note").innerHTML = sERR ~~~~~~~~Exit Sub ~~~~ElseIf sOTF = "" Then ~~~~~~~~sERR = "<b>" & sINF & "</b> is empty!" ~~~~~~~~document.getElementById("Note").innerHTML = sERR ~~~~~~~~Exit Sub ~~~~ElseIf sSAV = sOTF Then ~~~~~~~~sERR = "<b>" & sINF & "</b> not changed!" ~~~~~~~~document.getElementById("Note").innerHTML = sERR ~~~~~~~~Exit Sub ~~~~End If ~~~'* ~~~'*~~Copy ~~~'* ~~~~~~~~oFSO.CopyFile sINF, sINF & "." & sNOW ~~~'* ~~~'*~~Write ~~~'* ~~~~Set oOTF = oFSO.OpenTextFile(sINF,2,true) ~~~~~~~~oOTF.Write(sOTF) ~~~~Set oOTF = Nothing End Sub Sub Window_Onload() '**** '*~~List files. '**** ~~~~Call File_List() End Sub </script> <style type="text/css"> body,td,th { font-family:Arial; font-size:80% } ..butt { background-color:white; width:80px; height:22px } ..text { font-family:Courier; font-size:10pt } ..yell { background-color:yellow } </style> </head> <body> <table border="0" width="90%"> <tr valign="top"> ~~<td> ~~~~<b>Select a file:</b> ~~~~<br> ~~~~<span id="List"></span> ~~~~<br><br> ~~~~<span class="yell" id="Note"></span> ~~~~<br><br> ~~~~<b>Text to be inserted at cursor position:</b> ~~~~<br> ~~~~<textarea class="text" id="Entry" cols="30" rows="10" wrap="virtual" readonly>Hello World</textarea> ~~~~<br><br> ~~~~<input type="button" class="butt" value="Insert" onclick="File_Position()"> ~~~~ ~~~~<input type="button" class="butt" value="Replace" onclick="File_Replace()"> ~~~~ ~~~~<input type="button" class="butt" value="Exit" onClick="Self.Close()"> ~~~~<br><br> ~~~~<span id="Sect"></span> ~~</td> ~~<td> ~~~~<textarea class="text" id="Data" cols="72" rows="50" wrap="virtual"></textarea> ~~</td> </tr> </table> </body> </html> |
My System Specs![]() |
| | #12 (permalink) |
| | Re: Howto: Add lines of text from a specific point in a text file.. "McKirahan" <News@xxxxxx> wrote in message news:_6SdnVhxhsmxfv3VnZ2dnUVZ_v3inZ2d@xxxxxx [snip] Quote: > ~~~~<textarea class="text" id="Entry" cols="30" rows="10" wrap="virtual" > readonly>Hello World</textarea> ~~~~<textarea class="text" id="Entry" cols="30" rows="10" wrap="virtual"></textarea> |
My System Specs![]() |
| | #13 (permalink) |
| | Re: Howto: Add lines of text from a specific point in a text file.. One option: www.jsware.net/jsware/scripts.php3#classpk Inside the "class pack" download is a script INI class. You paste it into a script, or use ExecuteGlobal to include it into your script. You can then access INI files like objects. The class provides functions to write, delete, or return INI values ("keys") or sections. It's designed to mimic the Windows API functions for INI files. (GetPrivateProfileString, etc.) You don't need to parse the text of the INI at all. It's all done inside the class. |
My System Specs![]() |
| | #14 (permalink) |
| | Re: Howto: Add lines of text from a specific point in a text file.. In microsoft.public.scripting.vbscript message <B6KdnQBcwJjih_3VnZ2dnUVZ _hGdnZ2d@xxxxxx>, Mon, 23 Jun 2008 16:56:19, McKirahan <News@xxxxxx> posted: Quote: > dNOW = Now > sNOW = Year(dNOW) _ > & (10^8 * Month(dNOW)) _ > + (10^6 * Day(dNOW)) _ > + (10^4 * Hour(dNOW)) _ > + (10^2 * Minute(dNOW)) _ > + (10^0 * Second(dNOW)) I suspect that 10^4 means take 10 and raise it to the power 4. That might be slower than just writing 1e4; it's certainly longer. You take the year number and string-cat it with the extended month then implicitly numberise it to do the additions. That seems weird. dNOW = Now sNOW = 1e10 * Year(dNOW) _ + 10^8 * Month(dNOW) _ + 10^6 * Day(dNOW) _ + 10^4 * Hour(dNOW) _ + 10^2 * Minute(dNOW) _ + Second(dNOW) will generate a Number which when later catted will become a string. Or use repeated multiply-by-100 and add, with parentheses. A well-designed language would include a means of writing such expressions in RPN. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| read text file - but starting at a specific point (not the very first character of the very first line) | VB Script | |||
| Using lines in a text file | PowerShell | |||
| Removing lines from a text file | PowerShell | |||
| HowTo: Get Text from a file and put in a string. | PowerShell | |||
| removing first three lines in a text file | PowerShell | |||