mcfr1es Posted August 13, 2004 Posted August 13, 2004 (edited) Bitten off more than I can chew i think... After spending 50+ hours trying to figure out my first real scipt, (a relatively easy one according to most), I am looking for anyone who is willing to help me through this. In my script, The array $UserList has 50 items on it, I want the script to open a text file, check each item in my array against every item in the text file, and if it does not already exist in the text file, I wish it to be added. After all 50 items are either added or discarded, the $UserList array will recieve another 50 items to be sorted and so on many times. The problem that I encountered is that in order to check the array to the text file, the check must be in embedded for loops. This is where the problem lies -- if I try to add any lines of code such as counters or printers here, they will be done too many times (due to the loops) help? Edited August 13, 2004 by mcfr1es Roger! You son of a big pile o' Monkey Nuts.
mcfr1es Posted August 14, 2004 Author Posted August 14, 2004 Could you post the problem code? <{POST_SNAPBACK}>here it is: it doesnt print out results yet and the problem lies in these lines -> $f = $f + 1 ReDim $AllUsers [$f] TrayTip("tit","numnames= " & $numnames & " f= " & $f, 5, 1) $AllUsers [$f] = $UserList [$vv] they are being excecuted too many times (because of the for loops used to check if userlist = new names) I would need to take them out of the inside for loop but i cannot or the three lines would not be part of the if statement if I do so. QUESTION ON THAT TOPIC: I know that in java this cannot be done- For For If Next Endif Next (overlapping loops that is) does that still hold true for autoit? expandcollapse popup$numnames = 0 $runtime = 0 Dim $AllUsers [1] $f = 1 Dim $PageNames [ 50 ] [2000] $count = 0 $PageNames = _NameURL() For $aa = 1 to 24 Step 1 For $bb = 1 to 1001 Step 50 $sURL = $Pagenames [$aa] [$bb] $UserList = _GetUsers($sURL) $numnames = $numnames +50 For $vv = 1 to 50 If $runtime = 0 Then $f = $f+50 ReDim $AllUsers [$f] $AllUsers [$vv] = $UserList [$vv] Else For $uu = 1 to $numnames If $AllUsers [$uu] <> $UserList [$vv] Then $f = $f + 1 ReDim $AllUsers [$f] TrayTip("tit","numnames= " & $numnames & " f= " & $f, 5, 1) $AllUsers [$f] = $UserList [$vv] EndIf Next Endif Next $runtime = 1 Next Next $filename = "users.txt" FileOpen ($filename, 1) ;Check if file opened for writing OK If $filename = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileClose ($filename) Roger! You son of a big pile o' Monkey Nuts.
Bartokv Posted August 14, 2004 Posted August 14, 2004 (edited) If the script isn't too big, post what you have made so far within this thread and we'll try to help.FYI: Keeping all relevant posts within the same original thread also helps some with following issue continuity.Also, don't get too bogged down with loops. Remember that you can create and call functions from within themselves, and/or other functions. I find it useful to create a variable that I can use as a flag when I find something... Then if the flag is set, each loop/function will know to exit without wasting more ticks.I've also thrown together some snippets from the help doc to make the following example for you:expandcollapse popupDim $UserList[1] $DataFile = "names.txt" ScanFile($DataFile) $Output = "" For $user = 1 to (Ubound($UserList) - 1) $Output = $Output & $UserList[$user] & @CR Next MsgBox(4096, "User List", $Output) Exit ; Generates a listing of unique names Func Check($name) $Found = 0 $Len = Ubound($UserList) - 1 For $pos = 1 to $Len If StringInStr($UserList[$pos], $name) Then $Found = $pos ExitLoop EndIf Next If $Found = 0 Then $NewDim = $Len + 1 ReDim $UserList[$NewDim + 1] $UserList[$NewDim] = $name EndIf EndFunc ; Opens a file, and passes each line to Check() Func ScanFile($FileName) $file = FileOpen($FileName, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop Check(StringStripCR($line)) Wend FileClose($file) EndFuncHope this helps!Edit: Oops... Didn't see the last post when I started working on this one. Edited August 14, 2004 by Bartokv
mcfr1es Posted August 14, 2004 Author Posted August 14, 2004 ty so much for your help... I am so surprised you would take the time to create a sample script for me, ty so much again also, if you have time, would u be able to explain the use of stringstripcr? would the script not have worked if it wasnt there? why or why not? thanks again Roger! You son of a big pile o' Monkey Nuts.
Bartokv Posted August 14, 2004 Posted August 14, 2004 Sorry, I forgot to throw in comments... StringStripCR removes all carriage return characters from a given string. The script would still technically work, although the output could contain an extra blank line after each entry.If you have questions over any of the other commands, feel free to check out the help file for more detailed information:$HelpDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\HiddenSoft\AutoIt3", "InstallDir") If $HelpDir = "" Then ShowError() $HelpFile = Chr(34) & "START " & $HelpDir & "\AutoIt.chm" & Chr(34) Run(@ComSpec & " /c " & $HelpFile) Exit Func ShowError() MsgBox(48, "Help File", "Unable to determine AutoIt install path.") Exit EndFunc
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