Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send keys not send the correct character? 2

Status
Not open for further replies.

bct10

Technical User
May 3, 2004
37
US
I am use this script
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("Test.txt")
While oFile.AtEndOfStream <> True
strLine = oFile.ReadLine
If InStr(strLine, "REV") > 0 Then
arrParts = Split(strLine, "|")

End If
Wend

rem WScript.Echo arrParts(7)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate ("notepad")

WshShell.sendkeys arrParts(6)

WshShell.sendkeys ".txt"

the output I am getting is REVNPW>TXT

I would like to why i get a > when it should be a .
if rem out WshShell.sendkeys arrParts(6)
I get .txt thanks for an help you can give me on what i am doing wrong
 
Hello bct10,

Though seemingly related to the problem you mentioned, it might. Correct the following and run again see what happens.
Code:
'[COLOR=red]rem WScript.Echo arrParts(7)[/color]
'WScript.Echo arrParts(7)
Set WshShell = WScript.CreateObject("WScript.Shell")
[COLOR=green]WshShell.Run "notepad"[/color]
WshShell.AppActivate ("notepad")
I tested with simple file and it works, though I am not impressed with the sendkeys thing.

regards - tsuji
 
Also, a common problem which might result is the formatting character from the .txt which remains with the splitted array elements. You have to get rid of those which can easily escape visual inspection with .echo.

- tsuji
 
Hi tsuji
I tested with this scrips
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("Test.txt")
While oFile.AtEndOfStream <> True
strLine = oFile.ReadLine
If InStr(strLine, "REV") > 0 Then
arrParts = Split(strLine, "|")

End If
Wend

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate ("notepad")

WshShell.sendkeys arrParts(6)

WshShell.sendkeys ".txt"
an got REVNPW>TXT as output

here is the line in test.txt
2|CAZ071|Z|04 May 19:00|WIND|CA Lassen-Eastern Plumas-Eastern Sierra Counties (CAZ071)|REVNPW|4B0BB
thank for an help
 
Here are a couple of things I noticed about your script. First, you will only capture the information for the last instance of the string you search for because you do all of the work outside the While block. Second, Notepad must be open before you run the script. Lastly, when I ran the script with notepad open, I got the expected result of REVNPW.txt.

Here is what I think you want:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("Test.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Exec("notepad.exe")
WScript.Sleep(3000)
While oFile.AtEndOfStream <> True
	strLine = oFile.ReadLine
	If InStr(strLine, "REV") > 0 Then
		arrParts = Split(strLine, "|")
        WScript.Echo "Found"
        WshShell.AppActivate ("notepad")
		WshShell.sendkeys arrParts(6) 
		WshShell.sendkeys ".txt"
	End If
Wend

Actually I don't really think this is what you want. If what you want as a result is to have a text file with each of the found values on its own line, then you should be using the File object and writing directly to the file. You could even open the file in Notepad after you create it.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
bct10,

[1] How comes you got it running without adding the "green"-colored line I added up there? Could you add it there to test again?
[2] I run your sample file, and it's output is correct, REVNPW.txt (lower case for txt).
[3] Though my box here run ascii, yours might be default to unicode? But, I doubt it.
[4] Add another line inside the instr() if-end if. You do not want to capture the last occurrence or do you? Also always close out opened file's handle.
Code:
do While oFile.AtEndOfStream <> True
strLine = oFile.ReadLine
If InStr(strLine, "REV") > 0 Then
arrParts = Split(strLine, "|")
exit do        
End If
loop
oFile.close
- tsuji
 
tsuji's right about closing files. I really should start posting more code. I generally just post a snippet that focuses on the specific problem and thus doesn't always follow proper coding standards when used by itself.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Hi tom an tsuji
I have tried all ways an still get REVNPW>TXT
Tom what am do is aotomateing a windows progrm
thanks for any help
 
Please post the exact code you are using. I haven't had any problem getting it to work.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Hi tom this is my test.txt

[SETUP]
FILLSTYLE=0
OPACITY=60
SERVER_SPECIAL=True
BORDERWIDTH=1

[COLOURS]
OTHER_FILL=16711935
ADVISE_FILL=65535
WATCH_FILL=3972607
WARN_FILL=255
OTHER_BORDER=0
ADVISE_BORDER=0
WATCH_BORDER=0
WARN_BORDER=0

[SHAPES]
2|ARC001|C|04 May 16:00|FLOOD|AR Arkansas (ARC001)|LZKFFS|41c
2|ARC063|C|04 May 16:00|FLOOD|AR Independence (ARC063)|LZKFFS|41c
2|ARC067|C|04 May 16:00|FLOOD|AR Jackson (ARC067)|LZKFFS|41c
2|ARC075|C|04 May 16:00|FLOOD|AR Lawrence (ARC075)|LZKFFS|41c
2|ARC095|C|04 May 16:00|FLOOD|AR Monroe (ARC095)|LZKFFS|41c
2|ARC117|C|04 May 16:00|FLOOD|AR Prairie (ARC117)|LZKFFS|41c
2|ARC121|C|04 May 16:00|FLOOD|AR Randolph (ARC121)|LZKFFS|41c
2|ARC145|C|04 May 16:00|FLOOD|AR White (ARC145)|LZKFFS|41c
2|ARC147|C|04 May 16:00|FLOOD|AR Woodruff (ARC147)|LZKFFS|41c
2|CAZ071|Z|04 May 19:00|WIND|CA Lassen-Eastern Plumas-Eastern Sierra Counties (CAZ071)|REVNPW|4B0BB
2|CAZ072|Z|04 May 19:00|WIND|CA Greater Lake Tahoe Area (CAZ072)|REVNPW|4B0BB
2|CTZ005|Z|04 May 21:23|WX_MESSAGE|CT Northern Fairfield (CTZ005)|OKXRFW|49WEB
2|CTZ010|Z|04 May 21:23|WX_MESSAGE|CT Southern New Haven (CTZ010)|OKXRFW|49WGB
2|CTZ011|Z|04 May 21:23|WX_MESSAGE|CT Southern Middlesex (CTZ011)|OKXRFW|49WGB
2|CTZ012|Z|04 May 21:23|WX_MESSAGE|CT Southern New London (CTZ012)|OKXRFW|49WGB
2|ILC077|C|05 May 05:00|FLOOD|IL Jackson (ILC077)|PAHFFS|45oAA
2|LAC079|C|04 May 15:00|FLOOD|LA Rapides (LAC079)|LCHFFS|41o
2|NCZ001|Z|04 May 16:00|WX_MESSAGE|NC Ashe (NCZ001)|RNKNPW|37M
2|NCZ002|Z|04 May 16:00|WX_MESSAGE|NC Alleghany (NCZ002)|RNKNPW|37M
2|NCZ018|Z|04 May 16:00|WX_MESSAGE|NC Watauga (NCZ018)|RNKNPW|37M
2|NJZ005|Z|04 May 21:23|WX_MESSAGE|NJ Essex (NJZ005)|OKXRFW|49WAB
2|NJZ006|Z|04 May 21:23|WX_MESSAGE|NJ Hudson (NJZ006)|OKXRFW|49WAB
2|NJZ011|Z|04 May 21:23|WX_MESSAGE|NJ Union (NJZ011)|OKXRFW|49WAB
2|NJZ2|Z|04 May 21:23|WX_MESSAGE|NJ Western Passaic (NJZ2)|OKXRFW|49WEB
2|NVZ003|Z|04 May 19:00|WIND|NV Greater Reno-Carson City-Minden Area (NVZ003)|REVNPW|4B0BB
2|NVZ004|Z|04 May 19:00|WIND|NV Western Nevada Basin and Range including Pyramid Lake (NVZ004)|REVNPW|4B0CB
2|NVZ2|Z|04 May 19:00|WIND|NV Greater Lake Tahoe Area (NVZ2)|REVNPW|4B0BB
2|NYZ067|Z|04 May 21:23|WX_MESSAGE|NY Orange (NYZ067)|OKXRFW|49WEB
2|NYZ068|Z|04 May 21:23|WX_MESSAGE|NY Putnam (NYZ068)|OKXRFW|49WEB
2|NYZ069|Z|04 May 21:23|WX_MESSAGE|NY Rockland (NYZ069)|OKXRFW|49WEB
2|NYZ070|Z|04 May 21:23|WX_MESSAGE|NY Northern Westchester (NYZ070)|OKXRFW|49WEB
2|NYZ072|Z|04 May 21:23|WX_MESSAGE|NY New York (Manhattan) (NYZ072)|OKXRFW|49WAB
2|NYZ073|Z|04 May 21:23|WX_MESSAGE|NY Bronx (NYZ073)|OKXRFW|49WAB
2|NYZ074|Z|04 May 21:23|WX_MESSAGE|NY Richmond (Staten Is.) (NYZ074)|OKXRFW|49WAB
2|NYZ075|Z|04 May 21:23|WX_MESSAGE|NY Kings (Brooklyn) (NYZ075)|OKXRFW|49WAB
2|NYZ076|Z|04 May 21:23|WX_MESSAGE|NY Queens (NYZ076)|OKXRFW|49WAB
2|NYZ077|Z|04 May 21:23|WX_MESSAGE|NY Nassau (NYZ077)|OKXRFW|49WAB
2|NYZ079|Z|04 May 21:23|WX_MESSAGE|NY Northeast Suffolk (NYZ079)|OKXRFW|49WCB
2|NYZ081|Z|04 May 21:23|WX_MESSAGE|NY Southeast Suffolk (NYZ081)|OKXRFW|49WCB
2|TXC349|C|27 May 02:00|FLOOD|TX Navarro (TXC349)|FWDFFS|1GE
2|TXC355|C|04 May 22:00|FLOOD|TX Nueces (TXC355)|CRPFFS|3Mf
2|TXC409|C|04 May 22:00|FLOOD|TX San Patricio (TXC409)|CRPFFS|3Mf
2|VAZ009|Z|04 May 16:00|WX_MESSAGE|VA Smyth (VAZ009)|RNKNPW|37M
2|VAZ010|Z|04 May 16:00|WX_MESSAGE|VA Bland (VAZ010)|RNKNPW|37M
2|VAZ011|Z|04 May 16:00|WX_MESSAGE|VA Giles (VAZ011)|RNKNPW|37M
2|VAZ012|Z|04 May 16:00|WX_MESSAGE|VA Wythe (VAZ012)|RNKNPW|37M
2|VAZ013|Z|04 May 16:00|WX_MESSAGE|VA Pulaski (VAZ013)|RNKNPW|37M
2|VAZ014|Z|04 May 16:00|WX_MESSAGE|VA Montgomery (VAZ014)|RNKNPW|37M
2|VAZ015|Z|04 May 16:00|WX_MESSAGE|VA Grayson (VAZ015)|RNKNPW|37M
2|VAZ016|Z|04 May 16:00|WX_MESSAGE|VA Carroll (VAZ016)|RNKNPW|37M
2|VAZ017|Z|04 May 16:00|WX_MESSAGE|VA Floyd (VAZ017)|RNKNPW|37M
2|VAZ018|Z|04 May 16:00|WX_MESSAGE|VA Craig (VAZ018)|RNKNPW|37M
2|VAZ019|Z|04 May 16:00|WX_MESSAGE|VA Alleghany (VAZ019)|RNKNPW|37M
2|VAZ020|Z|04 May 16:00|WX_MESSAGE|VA Bath (VAZ020)|RNKNPW|37M
2|VAZ022|Z|04 May 16:00|WX_MESSAGE|VA Roanoke (VAZ022)|RNKNPW|37M
2|VAZ7|Z|04 May 16:00|WX_MESSAGE|VA Tazewell (VAZ7)|RNKNPW|37M
2|WVZ042|Z|04 May 16:00|WX_MESSAGE|WV Mercer (WVZ042)|RNKNPW|37M
2|WVZ043|Z|04 May 16:00|WX_MESSAGE|WV Summers (WVZ043)|RNKNPW|37M
2|WVZ044|Z|04 May 16:00|WX_MESSAGE|WV Monroe (WVZ044)|RNKNPW|37M
2|WVZ045|Z|04 May 16:00|WX_MESSAGE|WV Greenbrier (WVZ045)|RNKNPW|37M
4|AKZ018|Z|04 May 15:00|FREEZE|AK Taiya Inlet and Klondike Highway (AKZ018)|AJKNPW|3Nv
4|AKZ019|Z|04 May 15:00|FREEZE|AK Haines Borough and Lynn Canal (AKZ019)|AJKNPW|3Nv
4|AKZ020|Z|04 May 15:00|FREEZE|AK Glacier Bay (AKZ020)|AJKNPW|3Nv
4|AKZ021|Z|04 May 15:00|FREEZE|AK Eastern Chichagof Island (AKZ021)|AJKNPW|3Nv
4|AKZ025|Z|04 May 15:00|FREEZE|AK Jeneau Bororugh and Northern Admiralty Islan (AKZ025)|AJKNPW|3Nv
4|NCC017|C|04 May 13:00|FLOOD|NC Bladen (NCC017)|ILMFLW|41r

here is the code

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile("Test.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Exec("notepad.exe")
WScript.Sleep(3000)
While oFile.AtEndOfStream <> True
strLine = oFile.ReadLine
If InStr(strLine, "REV") > 0 Then
arrParts = Split(strLine, "|")
WScript.Echo "Found"
WshShell.AppActivate ("notepad")
WshShell.sendkeys arrParts(6)
WshShell.sendkeys ".txt"
End If
Wend
oFile.close

thanks for all help
 
And when you run this, what ends up in notepad?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
hi tom here what i get I went . were I get >

REVNPW>TXTREVNPW>TXTREVNPW.txtREVNPW>TXTREVNPW>TXT
 
Well then I have to admit that I am stumped. I don't expect it to work, but try changing this line:
WshShell.sendkeys ".txt"
to:
WshShell.sendkeys Chr(46) & "txt"

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
hi tom here what i got
REVNPW>TXTREVNPW.txtREVNPW.txtREVNPW>TXTREVNPW>TXT
is there a way to limet it to only show one entry so if
i have 3 with npw i only need 1
 
It looks like you are getting some sort of extraneous input. I see 3 REVNPW.txt entries. If you should be getting 3, then it looks like something else is inputting other info. To only get one (as long as the last one is OK) just move the part that rights to notepad outside of the While block.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
no go got REVNPW>TXT
is there any other way to send keyboard text to a program
or a way to move the mouse
thanks
 
REVNPW>TXT[red]REVNPW.txtREVNPW.txt[/red]REVNPW>TXTREVNPW>TXT

The part in red is right. So the question becomes: Where is the wrong output coming from?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
I do not know but here the fix
WshShell.sendkeys arrParts(6) & ".txt"
an that works fine
tom here my last question
lets say say
i have 3 enentrys in my text file one is
REVNPW

REVFFS

REVCEM

Is there a way to stop the search once it finds the first one then run thru the rest of the script then go back an do the next on and so on intel its done
thanks for all help
 
The best way to do what you want I think would be to put the rest of the script into a Sub or Function then call it and pass whatever info it needs to it.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
hi tom could you show me how
Sub or Function
so that it wood work like quesation above thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top