seandisanti Posted July 7, 2005 Share Posted July 7, 2005 here's the situation... we have a unix system that spools files to a network share. i'm making a little gui to take the footwork out of getting the spool files. the end result will be a small gui that will have a combo box that has each of the spool files for the given login. So far, i have it so that when the script is run, the html file listing the spools to choose from is saved to the harddrive with inetget() and then parsed for spool filenames. an array is built of the file names, and _ArrayDisplay() shows the elements exactly as i want them, 0 as 0, and each other element containing a spool file name. then a gui is created, right now the only control on the gui is the combo box. what i want to do, is before it's displayed, set the data on the combobox so that each populated element is given a spot, and the user can choose the appropriate spool file from the drop down. Sounds simple enough right? here's what i've tried so far...1) For....Next that creates a string by concatenating each of the elements of the array. for debugging i had a msgbox output the result, but the message box didn't come up, so the loop wasn't even entered. i double checked to make sure there wasn't a condition fail or anything, but the loop is not inside of any if statements, or any conditional block at all, the loop is just not executing, even though the gui creation code (everything except the include statements that are at the top of the script) comes after the loop and executes fine (with a blank combo box even though i have the GuiCtrlSetData before displaying the gui).2) Do...Until that operated pretty much the same way, it started by assigning the first populated array element to a variable, and then an iterator is incremented on each pass until it exceeds the highest index. each iteration adds "|" and the element at the index specified by the iterator. Again the string that was being created was blank after the loop completed, even though the variable was defined and assigned a value before the loop began so that it wouldn't lose scope.3) I found the _ArrayToString() function, and decided to try that with the delimiter of | or asc: 124. Same result as i received with the other loops.i obviously haven't found a solution that works, but i'm going to include my code here for ridicule.... er... suggestions... i apologize that it is sloppy, and i use msgbox's to test values alot, so there are alot of commented out msgbox's, and no other real comments... Can anyone tell me where i'm messing up on this?'************************************************************;code'************************************************************#include <Array.au3>#include <GUIConstants.au3>Opt("GUIOnEventMode", 1) ; on event mode$un = inputbox("Username","Enter your CUBS user name")$list = inetget("http://hpn1/cgi-bin/hpn1_uvsplist?mode=init&uvspn=&user=" & $un & "&date=&string=&action=Find+Spool+Files","c:\list.dat",1)if $list = 0 then$error = msgbox(0,"Error","The spool list was not generated, please use web interface to pull spool file")run("C:\Program Files\Internet Explorer\iexplore.exe http://hpn1/cgi-bin/hpn1_uvspool?mode=init")exitendif$input = fileopen("C:\list.dat",0)if @error = 1 then msgbox(0,"Error","Error opening file")endifif @error = -1 then msgbox(0,"Error","End of file")endif $chars = FileRead($input, 1)While 1 $chars = $chars & FileRead($input, 1) If @error = -1 Then ExitLoopWendfileclose($input)$counter = 1dim $SpoolFiles[1]do$spoolnum = stringinstr($chars,"/cgi-bin/hpn1_uvspfile?file=",0,$counter)if $spoolnum <> 0 then_ArrayAdd($SpoolFiles,stringmid($chars,$spoolnum + 28,15));msgbox(0,"spools","Spool #" & $counter & "= " & $SpoolFiles[$counter])$counter = $counter + 1endifuntil $spoolnum = 0;_ArrayDisplay( $SpoolFiles,"Spools")$cmbtxt = _ArrayToString($SpoolFiles,1,_ArrayMaxIndex($SpoolFiles),"|")msgbox(0,"progress",$cmbtxt)$mainwindow = GUICreate("Spool Puller", 500,200)GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")$cmb = GUICtrlCreateCombo("Spools For " & $un,150,-1,200)GUICtrlSetData($cmb,$cmbtxt)GUISetState(@SW_SHOW)While 1 Sleep(1000) ; Idle aroundWEndFunc CLOSEClicked() ExitEndFunc Link to comment Share on other sites More sharing options...
GaryFrost Posted July 7, 2005 Share Posted July 7, 2005 Take a look at your _ArrayToString line $cmbtxt = _ArrayToString($SpoolFiles, "|", 1, _ArrayMaxIndex($SpoolFiles)) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Valuater Posted July 7, 2005 Share Posted July 7, 2005 (edited) obviously you put some effort into this.... it's real hard to examine, read, and especially test other peoples scripts. normally we help with "smaller issues", however after studying on-line for 1/2 hour ( maybe i'm not the sharpest here..... like gafrost above) but, these are some areas of questionFirstYou say _ArrayDisplay() shows the elements exactly as i want them, 0 as 0,when I believe $Array[0] should show how many levels of $arrays there areSecondyou seem to go from $string to $array.... then to $string againI believe you can accomplish your goals without the $arrayThirdWhile 1 $chars = $chars & FileRead($input, 1) If @error = -1 Then ExitLoop Wendthis "FileRead" reads one charactor at a time... but you ad the $chars to each readCouldn't you just read the line with "FileReadLine" ???FourthA Could you please post your "list.dat" file so that I can see which file read to useB Could you post thew actual display of "_ArrayDisplay( $SpoolFiles,"Spools")" This could help others understand... not just me8)PS with all of that... it does not mean there isn't a better way to do this. 8) Edited July 7, 2005 by Valuater Link to comment Share on other sites More sharing options...
GaryFrost Posted July 7, 2005 Share Posted July 7, 2005 What Valuater said, I just didn't feel typing in all that after finding the line with the problem. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 obviously you put some effort into this.... it's real hard to examine, read, and especially test other peoples scripts. normally we help with "smaller issues", however after studying on-line for 1/2 hour ( maybe i'm not the sharpest here..... like gafrost above) but, these are some areas of questionFirstYou say when I believe $Array[0] should show how many levels of $arrays there areSecondyou seem to go from $string to $array.... then to $string againI believe you can accomplish your goals without the $arrayThirdWhile 1 $chars = $chars & FileRead($input, 1) If @error = -1 Then ExitLoop Wendthis "FileRead" reads one charactor at a time... but you ad the $chars to each readCouldn't you just read the line with "FileReadLine" ???FourthA Could you please post your "list.dat" file so that I can see which file read to useB Could you post thew actual display of "_ArrayDisplay( $SpoolFiles,"Spools")" This could help others understand... not just me8)PS with all of that... it does not mean there isn't a better way to do this. 8)<{POST_SNAPBACK}>definitely all good points...1) that's a good idea that you suggest having the number of elements stored in the first index, i hadn't thought of that, and it may help me later on down the line2) i need to be able to access whichever of the spool files is actually needed. the information is initially in a string which i have to pull out the filenames from. At that point i put them in an array so that i can keep track of them and use whichever of the elements i need later in the code. But in order to get them to display in combo box, i have to display them as a single string with the elements seperated by "|". 3)i use the fileread to pull it in one char at a time because the original file (will attach) is an html file without consistent line breaks, and depending on the number of spool files, the number of lines and files listed per line may vary. this just seemed like the most reliable way to make sure that it's all parsed out correctly. also the html files are pretty small so that part is done in less than a second.the attached file is the requested list.dat file. it is actually an html file generated by a server side script, but i saved it with the other extension for no good reason. the extension doesn't really matter for what i'm using it for though. you can open it with notepad or change extension to see the original page in your browser of choice Link to comment Share on other sites More sharing options...
GaryFrost Posted July 8, 2005 Share Posted July 8, 2005 Did your problem get solved? did you look at _ArrayToString? SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 Did your problem get solved? did you look at _ArrayToString?<{POST_SNAPBACK}>just got back in for the day, going to look at it now Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 Did your problem get solved? did you look at _ArrayToString?<{POST_SNAPBACK}>i couldn't find a problem with the _ArrayToString, but while i was looking at it, i decided to check the value in the _ArrayMaxIndex that is referenced in it, so i un-commented the _ArrayDisplay() and added another msgbox to display the value in the ArrayMaxIndex(), the max index is returning 0, and is not setting @error to reflect any kind of issue with obtaining the max index... i thought it could be an issue with the [0] element not having a value, so as per the suggestion above, i added the number of elements to that first element just to give it a value. the output is still the same, max index returns 0 even though the msgbox that appears immediately before it in the code shows 5 elements.... it looks like that is atleast part of my issue... i'm going to replace that with the $counter i used to build the array, not sure why i didn't do that in the first place...will let you know how it works out Link to comment Share on other sites More sharing options...
GaryFrost Posted July 8, 2005 Share Posted July 8, 2005 from the help file _ArrayToString ( $avArray, $sDelim [[, $iStart], $iEnd] ) you have _ArrayToString($SpoolFiles,1,_ArrayMaxIndex($SpoolFiles),"|") array,start,end,delem seems to me that is the wrong order. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 from the help file_ArrayToString ( $avArray, $sDelim [[, $iStart], $iEnd] )you have_ArrayToString($SpoolFiles,1,_ArrayMaxIndex($SpoolFiles),"|")array,start,end,delemseems to me that is the wrong order.<{POST_SNAPBACK}> this is what the help file shows.... (copy and paste)_ArrayToString ( $avArray, $iStart, $iEnd, $sDelim ) Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 oh yeah, but i was going to say i worked it out... i tried using "|" as the delimiter and chr(124) with no success. i ended up scrapping the ArrayToString completely in favor of a for loop that worked for me... here is the loop: $cmbtxt ="" for $x = 1 to $counter -1 $cmbtxt = $cmbtxt & $SpoolFiles[$x] & chr(124) next $cmbtxt = stringleft($cmbtxt,stringlen($cmbtxt)-1) msgbox(0,"Combo string",$cmbtxt);just to test output, worked successfully that worked for me. the output test showed how i wanted it to, and the setdata for the combo box updated perfectly. I'm finally ready to move on with the rest of the code. I really want to thank everyone for their input and help. Link to comment Share on other sites More sharing options...
Valuater Posted July 8, 2005 Share Posted July 8, 2005 i ended up scrapping the ArrayToString completelyGood choice!!! 8) Link to comment Share on other sites More sharing options...
seandisanti Posted July 8, 2005 Author Share Posted July 8, 2005 Good choice!!! 8)<{POST_SNAPBACK}>heh, i think so too. Now i have to do the crappy part though, the combo box uses inetget to grab a page, but the page doesn't save as pretty as doing a 'file>save as' on the actual page. When you do it that way, it comes all neatly formated, and it's super easy to parse out the page breaks etc. when you use the inetget() function though, it doesn't come formatted at all, and because the columns in the report vary in size and number (sometimes it's just one column of 6 characters, sometimes it's one of 6, and 3 others of varying lengths etc) i have to make the code pretty flexible... probably going to do that with another script so this one doesn't get any sloppier. Link to comment Share on other sites More sharing options...
Valuater Posted July 8, 2005 Share Posted July 8, 2005 heh, i think so too. Now i have to do the crappy part though, the combo box uses inetget to grab a page, but the page doesn't save as pretty as doing a 'file>save as' on the actual page. When you do it that way, it comes all neatly formated, and it's super easy to parse out the page breaks etc. when you use the inetget() function though, it doesn't come formatted at all, and because the columns in the report vary in size and number (sometimes it's just one column of 6 characters, sometimes it's one of 6, and 3 others of varying lengths etc) i have to make the code pretty flexible... probably going to do that with another script so this one doesn't get any sloppier.<{POST_SNAPBACK}>show me what this looks like8) Link to comment Share on other sites More sharing options...
seandisanti Posted July 11, 2005 Author Share Posted July 11, 2005 show me what this looks like8)<{POST_SNAPBACK}>actually it wasn't as bad as i thought, what was happening to mess up the format was that there were alot of @LF's without CR's... so reading the file in after saving with the filereadline() and writing it to a temp file fixed the format problem... here's the code though...and i'll even take a minute to document it....AutoItSetOption ("TrayIconHide",1);because this is being run from a second script, don't want to have another icon$input = fileopen("C:\source.txt",0);original file from inetget()$output = fileopen("C:\sourceo.txt",2);temp file $header = "";each page has a header, i want to take those out$counter = 0;kind of self explanitory right?while 1$chars = filereadline($input)if @error = -1 thenexitloopendifif (stringleft($chars,3) = " " and stringinstr($chars,"/") = 0) then;this checks to make sure the line being read is a valid data line, and not a line with html tags on it.filewriteline($output,$chars)$counter = $counter + 1elseif stringleft($chars,6) = "DEBTOR" then ;if it's not a data line, want to check if it's a header line because i need to save a header line for output$header = $chars;msgbox(0,"header",$header) this was one of my 'did i store the right thing' msgsendifendifwendfileclose($input)fileclose($output)$input = fileopen("C:\sourceo.txt",0);opening the output file to put the formatted data back into the original file$output = fileopen("C:\source.txt",2);reopening the original file for outputFilewriteline($output,$header);i want the column headers first, then all of the datawhile 1;begin dumping data$line = filereadline($input) if @error = -1 then exitloop endiffilewriteline($output,$line)wendfileclose($input)fileclose($output);msgbox(0,"Done","File Parsed")if $counter >= 65534 then;because some of the query results i'm working with have hundreds of thousands of lines, those can't be brought into excel with the 65536 row limitmsgbox(0,"Large File","File has more lines than excel can bring in. Opening file in notepad")run("notepad.exe c:\source.txt")elserun("C:\Program Files\Microsoft Office\Office\EXCEL.EXE")sleep(500)winactivate("Microsoft Excel")sleep(500)blockinput(1);don't want the user typing in excel and messing up next stepsend("^oc:\source.txt{ENTER 4}");i probably could have used dll's to do the file opening in excel a little prettier, but this is quicker than researching how to do thatblockinput(0);giving control back to the user...endif Link to comment Share on other sites More sharing options...
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