Re: I need a change to a Script
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Tue, 19 Feb 2008 09:05:19 -0600
"Calvo41" <calvo_xx@xxxxxxxxx> wrote in message
news:6DFEAD21-54CC-4008-A7BE-D2E53516AC25@xxxxxxxxxxxxxxxx
Some time ago, I got a script in this discussion group that works allright
for my needs: it takes a .txt document (named "lines.txt"), prompts for acan
line number, and puts the corresponding line in the clipboard, so that I
put it any where I want (any Web page, any text document, as the new nameof
a folder or file, etc...) just by pressing Ctrl+V. I use it repeatedly, inpast
one run session, alternating between the script and the page I want to
in (using Alt+Tab, for the purpose of alternating tasks).of
Now, I think that a change to the script could be useful: as, in the most
the cases, after having pasted a line I will need to past the next line ofline
"Lines.txt" ( that is, the lines are taken sequentially, from the first
to the last line), the script could be changed so that, when I have theon
script prompting for a line number, it could accept <Enter> (or the click
the <OK> button), without entering any number, meaning that the line to bea
put in the clipboard is the next line.
Actually, pressing <Enter> (or clicking the <OK> button), without entering
number, is used to end the working session with the script.now:
Here is the text for the .vbs script, I got here and I am using to work
[snip]
-------- Begin of the text-------------------
---------------------- End of the text ----------------------
Can any one change that text in a way that is suitable for my purpose?
Try this. Watch for word-wrap.
Enter 0 (zero) to retrieve the next line from the text file.
Enter a space or click the "Cancel" button to exit the script.
Option Explicit
'****
'* Prompts for a number and "cuts" that line from file "cTXT"
'* into the clipboard to "paste" it in another application.
'* "Alt+Tab" is used to alternate between the applications.
'*
'* The last line number entered is stored in file "cTMP" and,
'* if 0 is entered then it is retrieved and incremented by 1
'* and that line number is "cut" (copied) into the clipboard.
'****
'*
'* Declare Constants
'*
Const cVBS = "lines.vbs"
Const cTMP = "lines.tmp"
Const cTXT = "C:\lines.txt"
'*
'* Declare Variables
'*
Dim strBOX
Dim strOTF
Dim arrROW
Dim intROW
intROW = 0
Dim strROW
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
Dim objOTF
Dim objTMP
'*
'* Create temp file
'*
If Not objFSO.FileExists(cTMP) Then
Set objTMP = objFSO.CreateTextFile(cTMP)
objTMP.Write(intROW)
Set objTMP = Nothing
End If
'*
'* Read text file
'*
Set objOTF = objFSO.OpenTextFile(cTXT,1)
strOTF = objOTF.ReadAll
Set objOTF = Nothing
If Right(strOTF,Len(vbCrLf)) = vbCrLf Then
strOTF = Left(strOTF,Len(strOTF)-Len(vbCrLf))
End If
arrROW = Split(vbCrLf & strOTF, vbCrLf)
'*
'* Do until no input
'*
Do
'*
'* Input Line Number
'*
strBOX = "Enter a line number or letter;" & vbCrLf _
& vbTab & "(a-z = 1-26; A-Z = 27-52)." & vbCrLf & vbCrLf _
& "The input file contains " & UBound(arrROW) & " lines."
strBOX = Trim(InputBox(strBOX,cVBS,""))
If strBOX = "" Then Exit Do
If IsNumeric(strBOX) Then
intROW = CInt(strBOX)
If intROW = 0 Then
Set objTMP = objFSO.OpenTextFile(cTMP,1)
strROW = objTMP.ReadLine
Set objTMP = Nothing
If IsNumeric(strROW) Then
intROW = CInt(strROW)+1
End if
End If
Else
If strBOX >= "a" And strBOX <= "z" Then
intROW = Asc(strBOX) - 96
ElseIf strBOX >= "A" And strBOX <= "Z" Then
intROW = Asc(strBOX) - 64 + 26
Else
intROW = 0
End If
End If
'*
If intROW < 1 Or intROW > UBound(arrROW) Then
WScript.Echo "Invalid Line Number! " & intROW
Else
strROW = arrROW(intROW)
objIEA.Navigate "about:blank"
Do Until objIEA.ReadyState=4
WScript.Sleep 1
Loop
objIEA.Document.ParentWindow.ClipboardData.SetData "Text",
strROW
'WScript.Echo intROW & " = " & strROW
'*
'* Replace temp file
'*
objFSO.DeleteFile(cTMP)
Set objTMP = objFSO.CreateTextFile(cTMP)
objTMP.Write(intROW)
Set objTMP = Nothing
End If
Loop
'*
'* Quit
'*
objFSO.DeleteFile(cTMP)
Set objFSO = Nothing
objIEA.Quit
Set objIEA = Nothing
WScript.Quit
Uncomment (i.e. remove the single quote) from this line
'WScript.Echo intROW & " = " & strROW
to see what line number and line contents is in the clipboard
FYI: I am posting indented code but what you posted wasn't.
.
- References:
- I need a change to a Script
- From: Calvo41
- I need a change to a Script
- Prev by Date: I need a change to a Script
- Next by Date: The Best ADSI Editor????
- Previous by thread: I need a change to a Script
- Next by thread: The Best ADSI Editor????
- Index(es):
Loading