jimbeaurama Posted July 15, 2005 Posted July 15, 2005 Newbie question here. :"> BTW, awesome product! I am trying to write a script that will take a file with EDI transactions and parse it so that I can import it into Access. I have taken code from some examples on the forums and have gotten the script to do what I want, with the exception of separating individual UPCs into separate "transactions." I think I have that figured out; however, I have created an infinite loop in the script trying to accomplish this due to my lack of experience with scripting and loops. Code below is the script. I just added the While 2 loop (syntax may be wrong) and tried to run it. Wound up having to reboot. Any assistance is appreciated - I am sooo close I can taste it. expandcollapse popup#include <GuiConstants.au3> #include <file.au3> GUICreate("EDI 812 Parser", 371, 161, (@DesktopWidth-371)/2, (@DesktopHeight-161)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Continue = GUICtrlCreateButton("Continue...", 10, 130, 90, 20,$BS_DEFPUSHBUTTON ) $Exit = GUICtrlCreateButton("Exit", 140, 130, 90, 20) $About = GUICtrlCreateButton("About", 270, 130, 90, 20) $Header = GUICtrlCreateLabel("EDI 812 Parse Utility", 10, 0, 350, 40) GUICtrlSetFont(-1,25) GUISetState() Dim $YEAR = @YEAR Dim $MON = @MON Dim $MDAY = @MDAY Dim $MIN = @MIN Dim $File ;Open Word to perform first part of script Run("C:\Program Files\Microsoft Office\Office\WINWORD.EXE", "", @SW_MAXIMIZE) ; Wait for the Word to become active WinWaitActive("Document1 - Microsoft Word") ;initialize "Open" dialog Send("!fo") ;Wait for the window "Open" to not exist WinWaitClose("Open") $Title = WinGetTitle("") $FName = StringInStr($Title," - Microsoft Word") $NFile = StringLeft($Title,$FName) ;initialize macro to replace CRLFs Send("^8") ProcessWaitClose("WINWORD.EXE") While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg=$Continue GUISetState(@SW_SHOW,"EDI 812 Parser") Dim $TxnStrt,$CRChg,$StarChg,$BoxChg If $CmdLine[0] = 1 Then $file = $CmdLine[1] Else ; $file = FileOpenDialog("Open...", "C:\DATA\EDI", "All Files (*.*)", 1 + 2) $file = $NFile EndIf If @error Then Exit $linenum = _FileCountLines($file) $tempfile = "C:\DATA\EDI\TEMP-Parse.au3" $filetemp = "C:\DATA\EDI\TEMP-file.au3" _FileCreate($tempfile) _FileCreate($filetemp) While 1 ProgressOn("EDI Parser", "0% completed. Working...", "0 lines out of " & $linenum & " processed.",326,326, 16) WinActivate("EDI Parser","0% completed. Working...") For $i = 1 To $linenum $line = FileReadLine($file, $i) If @error = -1 Then ExitLoop Else $Text = StringReplace(StringReplace(StringReplace($line, "ST*812", @CRLF&"ST812"), "*", "@"), "", "@") FileWriteLine($tempfile, $Text) EndIf $per = Round(100 * $i / $linenum, 0) ProgressSet($per, $i & " lines out of " & $linenum & " processed.", $per & "% completed. Working...") Next ProgressSet("100",$linenum&" lines processed.", "100% completed.") Sleep(500) ProgressOff() WEnd ;Replace UPC indicators with transaction-specific info and break into separate transactions While 2 $numlines = _FileCountLines($tempfile) ProgressOn("EDI Parser", "0% completed. Working...", "0 lines out of " & $numlines & " processed.",326,326, 16) WinActivate("EDI Parser","0% completed. Working...") For $i = 1 To $numlines $tmpline = FileReadLine($tempfile, $i) If @error = -1 Then ExitLoop Else $chgText = StringReplace($tmpline, "@CDD", StringLeft($tmpline,STringInStr($tmpline,"@CDD","",1))) FileWriteLine($filetemp, $chgText) EndIf $per = Round(100 * $i / $linenum, 0) ProgressSet($per, $i & " lines out of " & $linenum & " processed.", $per & "% completed. Working...") Next ProgressSet("100",$linenum&" lines processed.", "100% completed.") Sleep(500) ProgressOff() MsgBox(0, "DONE!", "Processing Complete!") $newfile=FileSaveDialog("Save edited file as...","C:\DATA\EDI","Text Files (*.txt)",16,"REV-"&$file) FileCopy($filetemp,$newfile,1) Exit WEnd Case $msg=$About MsgBox(8256,"About","EDI Parser v2" & @CRLF & "By Kolin Paulk and"& @CRLF &"Jim Raleigh" & @CRLF & "Friday, July 15, 2005") Case $msg=$Exit Exit EndSelect WEnd Exit
Lord_Doominik Posted July 16, 2005 Posted July 16, 2005 hm very confusing and a bat style with your wends in the wend and select case... i think while wend loops do't work, if you got an select case running... you should have to take an endselect before the 2nd while and after the last you have to make a new select...
w0uter Posted July 16, 2005 Posted July 16, 2005 use TrayIconDebug Or MsgBox OR ConsoleWrite to see where it locks up. i presonaly would use console write. and if i didnt have scite msgbox. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
Lord_Doominik Posted July 16, 2005 Posted July 16, 2005 hm, but the debuggers dont work always soo fine... try it first with the correctins i gave... that shoukld work... if not, let the debugger check it...
jimbeaurama Posted July 16, 2005 Author Posted July 16, 2005 hm very confusing and a bat style with your wends in the wend and select case... i think while wend loops do't work, if you got an select case running... you should have to take an endselect before the 2nd while and after the last you have to make a new select...<{POST_SNAPBACK}> I'm not sure using Selects and Whiles are the correct way to go about this either. I was able to get the first two parts to work (edit in Word and then run the first find/replace to replace the delimiters) but could not figure out how to break multiple-UPC invoices into separate records. Then I thought that Autoit should be able to accomplish this based on how it searches strings . However, I can't find anything on how to run multiple scripts in sequence. I*think* that there must be some way to do it, but I am currently WAY over my head. Any direction would be appreciated.I tried putting another Select on the second loop, but the error message stated that the End Select I put there could not find the Select. Do I just need to create an additional script, or is there some way to ensure the sequential nature of this? Do I have the temp files created in the right places? Is that second search and replace function going to work? (I need to break it out separately to test, I imagine).My head is spinning , but there has to be some way to do this.
quaizywabbit Posted July 16, 2005 Posted July 16, 2005 make each 'while/wend' loop (the code between that is) a separate function. the first function would have to Return before the second function is called. [u]Do more with pre-existing apps![/u]ANYGUIv2.8
jimbeaurama Posted July 17, 2005 Author Posted July 17, 2005 make each 'while/wend' loop (the code between that is) a separate function.the first function would have to Return before the second function is called.<{POST_SNAPBACK}> You folks are GREAT!!!!By Jove, I do believe I've got it!Need to test it on a larger file (we receive roughly 3,000 invoices per week), but it looks like it is going to work.THANK YOUTHANK YOUTHANK YOU
jimbeaurama Posted July 25, 2005 Author Posted July 25, 2005 make each 'while/wend' loop (the code between that is) a separate function.the first function would have to Return before the second function is called.<{POST_SNAPBACK}>One last BASIC question....Everything seems to be working now. However, I have put the following If into the script to skip the transaction batch headers and footers:For $i = 1 To $numlines $tmpline = FileReadLine($tempfile, $i) If @error = -1 Then ExitLoop ElseIf StringLeft($tmpline,5) = "ISA00" OR StringLeft($tmpline,4) = "IEA@" then $i=$i+1 Else My qusestion is, does the $i=$i+1 go to the NEXT line, or SKIP the next line? Everything else seems to be working. Thanks for your help.
seandisanti Posted July 25, 2005 Posted July 25, 2005 (edited) One last BASIC question....Everything seems to be working now. However, I have put the following If into the script to skip the transaction batch headers and footers:For $i = 1 To $numlines $tmpline = FileReadLine($tempfile, $i) If @error = -1 Then ExitLoop ElseIf StringLeft($tmpline,5) = "ISA00" OR StringLeft($tmpline,4) = "IEA@" then $i=$i+1 Else My qusestion is, does the $i=$i+1 go to the NEXT line, or SKIP the next line? Everything else seems to be working. Thanks for your help.<{POST_SNAPBACK}>rather than $i=$i+1 you may want to ElseIf StringLeft($tmpline,5) = "ISA00" OR StringLeft($tmpline,4) = "IEA@" then ContinueLoop Else Edited July 25, 2005 by cameronsdad
jimbeaurama Posted July 26, 2005 Author Posted July 26, 2005 rather than you may want to ElseIf StringLeft($tmpline,5) = "ISA00" OR StringLeft($tmpline,4) = "IEA@" then ContinueLoop Else<{POST_SNAPBACK}>Did not realize there was a ContinueLoop command. I will try that. Thanks!
herewasplato Posted July 26, 2005 Posted July 26, 2005 After you get all of this working - lets change it all around and break it :-) Seriously, there are a few questions that I debated asking about: What format is the info in when you start? Are you opening a text file in Word or is it a Word doc file format to start with? If it is text - then you should be able to perform this: ";initialize macro to replace CRLFs" within AutoIt without Word. If the info that you start with is already a Word doc, then there might be a way to perfrom that same step without opening Word - but might not be worth changing your working code for that gain. ...and another thing :-) If you stick with using Word, consider this one minor change to this section of your code: ;initialize "Open" dialog Send("!fo") ;Wait for the window "Open" to exist WinWait("Open") ;Wait for the window "Open" to not exist WinWaitClose("Open") The help file for WinWaitClose states, "The window is polled every 250 milliseconds or so". I'm not sure that the just having the two lines that you had will always work for you... I might not fully understand the WinWaitClose function, but it seems to me that it is possible for a delay to occur on some computers that might cause the "Open" dialog box to not appear soon enough. In that case, the script might evaluate the "non-existance" of the "Open" dialog box and proceed before the "Open" dialog box ever existed. clear as mud? [size="1"][font="Arial"].[u].[/u][/font][/size]
jimbeaurama Posted July 28, 2005 Author Posted July 28, 2005 After you get all of this working - lets change it all around and break it :-)Yeah-Yeah. Cool. I need to break it anyway because I am having problems... Seriously, there are a few questions that I debated asking about:What format is the info in when you start? Are you opening a text file in Word or is it a Word doc file format to start with?file is a raw extract of EDI812 information. file comes through with hard line breaks at the end of each line that I cannot get rid of. I tried ASCII, @CR, @LF, @CRLF, Char(), Chr(). Frustrating.If it is text - then you should be able to perform this:";initialize macro to replace CRLFs" within AutoIt without Word.If the info that you start with is already a Word doc, then there might be a way to perfrom that same step without opening Word - but might not be worth changing your working code for that gain.willing to do that if I could figure out how to do it......and another thing :-)If you stick with using Word, consider this one minor change to this section of your code:;initialize "Open" dialogSend("!fo");Wait for the window "Open" to existWinWait("Open");Wait for the window "Open" to not existWinWaitClose("Open")The help file for WinWaitClose states, "The window is polled every 250 milliseconds or so". I'm not sure that the just having the two lines that you had will always work for you... I might not fully understand the WinWaitClose function, but it seems to me that it is possible for a delay to occur on some computers that might cause the "Open" dialog box to not appear soon enough. In that case, the script might evaluate the "non-existance" of the "Open" dialog box and proceed before the "Open" dialog box ever existed.clear as mud?<{POST_SNAPBACK}> Having issues with passing macro keys, as well as passing filename to the next function. I will have to post the script when I get back to my work computer. There is most likely a better solution, but I had to at least prove that the concept (parsing EDI transactions into a relational format for the purpose of loading a database) was viable. Now that I know that it is, and that a simple sales guy proved the point , it will make it easier to justify leveraging IT resources against the project.Thanks for y'alls' help. I can't say enough that this is a NEAT tool!
herewasplato Posted July 28, 2005 Posted July 28, 2005 ...file is a raw extract of EDI812 information. file comes through with hard line breaks at the end of each line that I cannot get rid of. I tried ASCII, @CR, @LF, @CRLF, Char(), Chr()...<{POST_SNAPBACK}>Manually open the file in Word without running the marco against it. Go to File > Properties > General tab and tell me what Word thinks the file type is.If the file type is "Plain Text document...", then take a look at FileReadLine in the AutoIt3 help file and the sample script at the bottom of that page. Also note the remarks:Returns the text of the line read, any newline characters ( CHR(10) or @LF ) at the end of a line read in are automatically stripped.As for my comment about editing a word doc without opening it. I could not locate that post - but I know it is out there somewhere.later... [size="1"][font="Arial"].[u].[/u][/font][/size]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now