Source language: Translate to:

SendKeys to an external file to remove characters

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

SendKeys to an external file to remove characters

Postby billc » Tue Sep 21, 2010 1:47 pm

Hi.

So I have this external *.csv file that contains data elements that each have a pair of quotation marks surrounding them, as in...

"IT-795","8922.46"
"IT-833","636.25"
"IT-839","11112.58"
"IT-841","34530.13"

I need to remove all of the quotation marks but keep the data and commas.

I've tried, without success, the following:

1. After copying the *.csv file to *.txt so NeoBook commands will work with the file, I copied the file contents to a variable (FileToVar) and then using StrReplace to remove the quotes (replacing them with ""), then writing the variable contents into the file with the All parameter. Using DebugBreakPoint to check each action, the quotes are not removed and the file ends up empty. So obviously the file contents are not being copied into the variable or the StrReplace isn't working on the variable or the variable sans-quotes is not being entered into the file...or all of the above. Here's the code:

FileToVar "C:\Temp\bill_card_export.txt" "[csvFileContent]"
StrReplace "[csvFileContent]" "[#34]" "" "[csvFileContentClean]" ""
FileWrite "C:\Temp\bill_card_export.txt" "All" "[csvFileContentClean]"

2. I've tried using hpwSendKeys with the following code:

Run "C:\Windows\notepad.exe" "c:\temp\bill_card_export.csv" "RunOnce+LoadComplete" "" "[RunningWindow]"
SendKeys "[RunningWindow]" "{CtrlDn}h{CtrlUp}"
hpwSendKeysToTitle "Replace" "^h[#34]%a"
SendMenuCommand "[RunningWindow]" "File,Save"
SendMenuCommand "[RunningWindow]" "File,Exit"

Nothing is replaced but the Replace dialog box remains open waiting for input.

3. I've tried several other things but I can't recall exactly what and I no longer have the code snippets.

All I want to do is remove the quotation marks throughout the entire file. There are about 400 data entries in the file right now but there could be more.

I've had nothing but trouble using SendKeys. It's as if the apps are invisible to the command or vice versa.

I've also searched through this forum for potential solutions to this problem and for SendKeys use in general and I've only found a few specific issues. Either I'm dumber than a rock or few other people seem to be using this action command.

Any suggestions or explanations of how I'm using the NeoBook commands improperly?

Eagerly awaiting your response(s).

bc
billc
 
Posts: 28
Joined: Fri Jul 30, 2010 1:46 pm

Postby Gaev » Tue Sep 21, 2010 3:25 pm

billc:

a) You don't need to rename files to .txt in order for NeoBook to FileRead or FileWrite them.

b) Your code (in section 1) looks just fine ... you can try the following refinements and snoping enhancements ...
Code: Select all
FileToVar "!C:\Temp\bill_card_export.txt" "[csvFileContent]"
AlertBox "Before" "[csvFileContent]"
SearchStr "[#34]" "[csvFileContent]" "[QuotePos]"
AlertBox "Quote Position" "[QuotePos]"
StrReplace "[csvFileContent]" "[#34]" "" "[csvFileContentClean]" ""
AlertBox "After" "[csvFileContentClean]"
FileWrite "!C:\Temp\bill_card_export.txt" "All" "[csvFileContentClean]"

a) Note the ! marks before the C:

b) Helps if the file is not too large to begin with ... or the AlertBoxes might be difficult to manage

c) If the Quote Position AlertBox returns 0, perhaps those are NOT Double Quotes
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby HPW » Tue Sep 21, 2010 10:58 pm

Try this:
Code: Select all
Run "C:\Windows\notepad.exe" "c:\temp\bill_card_export.csv" "RunOnce+LoadComplete" "" "[RunningWindow]"
SendKeys "[RunningWindow]" "{CtrlDn}h{CtrlUp}"
hpwSendKeysToTitle "Replace" "[#34][#9][#13][#254]l[#255][#27]"


[#34]=quotation mark
[#9]= Tab to next filed
[#13]= Enter
[#254]l[#255]= ALT L for all (Maybe different on other languages of windows)
[#27]= Esc to leave dialog
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

SendKeys to an External File

Postby billc » Wed Sep 22, 2010 2:39 pm

Thank you both!!!

I tried Gaev's and it worked but (although I could have sworn I did just that, except for the exclamation marks, which I didn't have to use anyway...strange), just for my own benefit, I'll try yours, HPW. By the way, I appreciate your message box alternative. When you next update it, could you add an option to have no button but just a time-out? I find that I use informational messages more than anything else and that would be great!

I wonder if you two have ever thought about creating an ebook on all you know about NeoBook. I mean, isn't you two who answer most of the questions on this forum? Might save you a lot of duplication of effort and I'd buy it (if you combined your knowledge) or them (if you each wrote one). Just a thought....
billc
 
Posts: 28
Joined: Fri Jul 30, 2010 1:46 pm

Postby HPW » Wed Sep 22, 2010 10:30 pm

I appreciate your message box alternative.


What do you mean with this 'message box alternative'?
Hans-Peter
User avatar
HPW
 
Posts: 2520
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

MessageBox Alternative

Postby billc » Thu Sep 23, 2010 7:31 am

Aaaaaaaaaachk! My bad.

I was so used to seeing your hpw plug-ins for NeoBook that I assumed the messagebox plug-in was yours as well but I just checked it out to be sure and discovered that it's an "ae" product (ae_NeoMsg), not "hpw."

Sorry 'bout that.
billc
 
Posts: 28
Joined: Fri Jul 30, 2010 1:46 pm


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Bing [Bot] and 1 guest