Kovitt Posted July 22, 2008 Posted July 22, 2008 (edited) Hello, I have been having quite a lot of issues with my for loops. They never work, and I then switch to while loops which work great. The problem I am having now to my knowledge cant be done with while loops. Am I doing something wrong? For $x=0 to Ubound($ce_id) - 1 For $i=0 to Ubound($Jobs) - 1 if $ce_id[$x] >= $RangeS[$i] and $ce_id[$x] <= $RangeE[$i] Then $Job_Instance[$i] = $Job_Instance[$i] + $CEID_Instance[$x] Exitloop EndIf Next Next This is an example of my ce_id array: (can be anywhere form 0-999999999) 12000 12001 12004 12005 12007 12008 12033 12045 Here is an example of my RangeS and RangeE arrays: 1 10001 351 51001 55001 60001 60001 65001 350 5100 10000 55000 60000 65000 9999999999 Edit: I forgot my array question. Is there a way to get rid of the empty spaces in my array? Thanks for the help. Edited July 23, 2008 by Kovitt
CoePSX Posted July 22, 2008 Posted July 22, 2008 If you're trying to populate a new array based on the results of these loops, you could check the _ArrayAdd function. [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font]
Kovitt Posted July 22, 2008 Author Posted July 22, 2008 When I use _ArrayAdd($Job_Instance, $Job_Instance[$i] + $CEID_Instance[$x]) The array is empty... I know that there should be results.
PsaltyDS Posted July 22, 2008 Posted July 22, 2008 When I use _ArrayAdd($Job_Instance, $Job_Instance[$i] + $CEID_Instance[$x]) The array is empty... I know that there should be results. Please post a short, complete, reproducer script for your issue. Declare your arrays with a short list of sample data in them, process them and display the result. There is nothing wrong with the functions you are having trouble with. We can't see what you are doing wrong without some code to demonstrate it. muttley Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kovitt Posted July 22, 2008 Author Posted July 22, 2008 (edited) expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> Global $x, $c = 0, $test, $msg, $size, $count, $Num_Lines, $Line, $path Dim $jobs[30000], $ce_id[500], $instance[5], $CEID_Instance[500], $Job[500], $RangeS[500], $RangeE[500] Dim $Job_Instance[500] Dim $count2 = 0 Dim $count3 = 0 For $x=0 to 499 $Job_Instance[$x] = 0 Next $path = FileOpen("RollupJobs.txt",0) While True $Line = filereadline($path) if @error = -1 then exitloop $instance = StringRegExp($Line,'([0-9]{1,})(?:\s{1,})([0-9]{1,})',1) If @error = 0 then $ce_id[$count3] = $instance[0] $CEID_Instance[$count3] = $instance[1] $count3 += 1 EndIf Wend $pathJ = FileOpen("Jobs.txt",0) While True $LineJ = FileReadLine($PathJ) If @error = -1 Then ExitLoop EndIf $a_sre = StringRegExp($LineJ, "([0-9]{1,})(?:\s{1,})(?:IFACT.Call_Rollup_Pkg.Call_Rollup_Proc\W)([0-9]{1,})(?:, )([0-9]{1,})", 3) if @error = 0 Then $Job[$count] = $a_sre[0] $RangeS[$count] = $a_sre[1] $RangeE[$count] = $a_sre[2] $count += 1 EndIf WEnd ;################################################################################################### For $x=0 to Ubound($ce_id) - 1 For $i=0 to Ubound($Jobs) - 1 if $ce_id[$x] >= $RangeS[$i] and $ce_id[$x] <= $RangeE[$i] Then $Job_Instance[$i] = $Job_Instance[$i] + $CEID_Instance[$x] Exitloop EndIf Next Next ;#################################################################################################### _ArrayDisplay($Job_Instance) Edit: Cleaning up code This is an abridged version of the scriptRollupJobs.txtJobs.txt Edited July 22, 2008 by Kovitt
PsaltyDS Posted July 22, 2008 Posted July 22, 2008 CODE#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> Global $x, $c = 0, $test, $msg, $size, $count, $Num_Lines, $Line, $path Dim $jobs[30000], $ce_id[500], $instance[5], $CEID_Instance[500], $Job[500], $RangeS[500], $RangeE[500] Dim $Job_Instance[500] Dim $count2 = 0 Dim $count3 = 0 For $x=0 to 499 $Job_Instance[$x] = 0 Next $path = FileOpen("RollupJobs.txt",0) While True $Line = filereadline($path) if @error = -1 then exitloop $instance = StringRegExp($Line,'([0-9]{1,})(?:\s{1,})([0-9]{1,})',1) If @error = 0 then $ce_id[$count3] = $instance[0] $CEID_Instance[$count3] = $instance[1] $count3 += 1 EndIf Wend $pathJ = FileOpen("Jobs.txt",0) While True $LineJ = FileReadLine($PathJ) If @error = -1 Then ExitLoop EndIf $a_sre = StringRegExp($LineJ, "([0-9]{1,})(?:\s{1,})(?:IFACT.Call_Rollup_Pkg.Call_Rollup_Proc\W)([0-9]{1,})(?:, )([0-9]{1,})", 3) if @error = 0 Then $Job[$count] = $a_sre[0] $RangeS[$count] = $a_sre[1] $RangeE[$count] = $a_sre[2] $count += 1 EndIf WEnd ;################################################################################################### For $x=0 to Ubound($ce_id) - 1 For $i=0 to Ubound($Jobs) - 1 if $ce_id[$x] >= $RangeS[$i] and $ce_id[$x] <= $RangeE[$i] Then $Job_Instance[$i] = $Job_Instance[$i] + $CEID_Instance[$x] Exitloop EndIf Next Next ;################################################################################################### # _ArrayDisplay($Job_Instance)Edit: Cleaning up code muttley This is an abridged version of the script To start off, make your life much easier by just reading the file into an array in one stroke with _FileReadToArray(), and drop the whole FileOpen()/FileReadLine() loop. Just loop through the array. Before processing data, you can pre-process the array by walking it backwards and deleting elements that are empty, for example: Global $avFile _FileReadToArray("RollupJobs.txt", $avFile) For $n = $avFile[0] To 1 Step -1 If StringStripWS($avFile[$n], 8) = "" Then _ArrayDelete($avFile, $n) Next $avFile[0] = UBound($avFile) - 1 _ArrayDisplay($avFile, "$avFile") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
andybiochem Posted July 22, 2008 Posted July 22, 2008 (edited) Hi,Not sure exactly what you need to accomplish, but like PsaltyDS said, use FileReadToArray.As an example, this is how you might want to populate your $Job, $RangeS, and $RangeE from your jobs.txt file...Dim $JobsTXTarray[1] Dim $Job[1] Dim $RangeE[1] Dim $RangeS[1] _FileReadToArray("jobs.txt",$JobsTXTarray) For $i = 1 to (UBound($JobsTXTarray) - 1) $match = StringRegExp($JobsTXTarray[$i], "([0-9]{1,})(?:\s{1,})(?:IFACT.Call_Rollup_Pkg.Call_Rollup_Proc\W)([0-9]{1,})(?:, )([0-9]{1,})", 3) if @error = 0 Then ;if matches are found... _ArrayAdd($Job,$match[0]) _ArrayAdd($RangeS,$match[1]) _ArrayAdd($RangeE,$match[2]) EndIf Next _ArrayDisplay($Job) _ArrayDisplay($RangeE) _ArrayDisplay($RangeS)..your regexp might be wrong, but I'm no expert. Try a more simple StringMid() to capture the CE_ID and INSTANCES from the file.scrap the regexp error, it DOES work - my fault muttley NOTE: the 'edit' function of this forum is as buggy as hell! Edited July 22, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Kovitt Posted July 22, 2008 Author Posted July 22, 2008 (edited) Thanks for the responces! The problem I am having is not with the arrays. In the 2 forloops at the end of the script, it takes the ce_id and if it is between ranges and rangeE it is supposed to add ceid_instance to Job_instance. The problem is no matter what RangeE is, in the second time through the nested for loop it will always do it in the second space of the array. Replace the loops with For $x=0 to Ubound($ce_id) - 1 For $i=0 to Ubound($Jobs) - 1 msgbox(0, "Info", $ce_id[$x] & @Crlf & $RangeS & $RangeE) if $ce_id[$x] >= $RangeS[$i] and $ce_id[$x] <= $RangeE[$i] Then $Job_Instance[$i] = $Job_Instance[$i] + $CEID_Instance[$x] Exitloop EndIf Next Next and you will see what I mean. Watch the second and third message box as the script runs( look at ce_id and RangeE. Thanks again for all the help guys! muttley Edit: Typo Edited July 22, 2008 by Kovitt
andybiochem Posted July 22, 2008 Posted July 22, 2008 Sort of understand, I think. Does this work.... expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> ;----- POPULATE CE_ID ARRAYS ----- Dim $RollUpJobsTXTarray[1] Dim $ce_id[1] Dim $CEID_Instance[1] _FileReadToArray("RollupJobs.txt",$RollUpJobsTXTarray) For $i = 1 to (UBound($RollUpJobsTXTarray) - 1) $match = StringRegExp($RollUpJobsTXTarray[$i],'([0-9]{1,})(?:\s{1,})([0-9]{1,})',1) If @error = 0 then ;if matches are found... _ArrayAdd($ce_id,$match[0]) _ArrayAdd($CEID_Instance,$match[1]) EndIf Next ;_ArrayDisplay($ce_id) ;_ArrayDisplay($CEID_Instance) ;----- POPULATE RANGE ARRAYS ----- Dim $JobsTXTarray[1] Dim $Job[1] Dim $RangeE[1] Dim $RangeS[1] _FileReadToArray("jobs.txt",$JobsTXTarray) For $i = 1 to (UBound($JobsTXTarray) - 1) $match = StringRegExp($JobsTXTarray[$i], "([0-9]{1,})(?:\s{1,})(?:IFACT.Call_Rollup_Pkg.Call_Rollup_Proc\W)([0-9]{1,})(?:, )([0-9]{1,})", 3) if @error = 0 Then ;if matches are found... _ArrayAdd($Job,$match[0]) _ArrayAdd($RangeS,$match[1]) _ArrayAdd($RangeE,$match[2]) EndIf Next ;_ArrayDisplay($Job) ;_ArrayDisplay($RangeE) ;_ArrayDisplay($RangeS) ;----- COMPARE EACH CE_ID WITH EACH RANGE ----- Dim $Job_Instance[1] For $i = 1 to (UBound($ce_id) - 1) For $j = 1 to (UBound($RangeE) - 1) If Number($ce_id[$i]) >= Number($RangeS[$j]) And Number($ce_id[$i]) <= Number($RangeE[$j]) Then _ArrayAdd($Job_Instance,$CEID_Instance[$i]) ExitLoop EndIf Next Next _ArrayDisplay($Job_Instance) Sorry, had to re-write your script to make it easier for thicky me to understand. muttley - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Kovitt Posted July 22, 2008 Author Posted July 22, 2008 Sort of understand, I think. Does this work.... expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> ;----- POPULATE CE_ID ARRAYS ----- Dim $RollUpJobsTXTarray[1] Dim $ce_id[1] Dim $CEID_Instance[1] _FileReadToArray("RollupJobs.txt",$RollUpJobsTXTarray) For $i = 1 to (UBound($RollUpJobsTXTarray) - 1) $match = StringRegExp($RollUpJobsTXTarray[$i],'([0-9]{1,})(?:\s{1,})([0-9]{1,})',1) If @error = 0 then ;if matches are found... _ArrayAdd($ce_id,$match[0]) _ArrayAdd($CEID_Instance,$match[1]) EndIf Next ;_ArrayDisplay($ce_id) ;_ArrayDisplay($CEID_Instance) ;----- POPULATE RANGE ARRAYS ----- Dim $JobsTXTarray[1] Dim $Job[1] Dim $RangeE[1] Dim $RangeS[1] _FileReadToArray("jobs.txt",$JobsTXTarray) For $i = 1 to (UBound($JobsTXTarray) - 1) $match = StringRegExp($JobsTXTarray[$i], "([0-9]{1,})(?:\s{1,})(?:IFACT.Call_Rollup_Pkg.Call_Rollup_Proc\W)([0-9]{1,})(?:, )([0-9]{1,})", 3) if @error = 0 Then ;if matches are found... _ArrayAdd($Job,$match[0]) _ArrayAdd($RangeS,$match[1]) _ArrayAdd($RangeE,$match[2]) EndIf Next ;_ArrayDisplay($Job) ;_ArrayDisplay($RangeE) ;_ArrayDisplay($RangeS) ;----- COMPARE EACH CE_ID WITH EACH RANGE ----- Dim $Job_Instance[1] For $i = 1 to (UBound($ce_id) - 1) For $j = 1 to (UBound($RangeE) - 1) If Number($ce_id[$i]) >= Number($RangeS[$j]) And Number($ce_id[$i]) <= Number($RangeE[$j]) Then _ArrayAdd($Job_Instance,$CEID_Instance[$i]) ExitLoop EndIf Next Next _ArrayDisplay($Job_Instance) Sorry, had to re-write your script to make it easier for thicky me to understand. muttley I have tried that to no avail.
andybiochem Posted July 22, 2008 Posted July 22, 2008 I have tried that to no avail. muttley Does it not work, or does it just give the wrong results? I get this array... that is a list of the CE_ID Instances whose CE_ID is between the ranges in the jobs.txt file is that what you wanted? - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 Does it not work, or does it just give the wrong results? I get this array... that is a list of the CE_ID Instances whose CE_ID is between the ranges in the jobs.txt file is that what you wanted? muttleyIncorrect results. Only $Job_Instance[2] is populated and it is like 14000 something Im not at work right now i will give a more detailed answer in the morning.
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 Does it not work, or does it just give the wrong results? I get this array... that is a list of the CE_ID Instances whose CE_ID is between the ranges in the jobs.txt file is that what you wanted? muttleyIncorrect results. Only $Job_Instance[2] is populated and it is like 14000 something Im not at work right now i will give a more detailed answer in the morning.
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 Incorrect results. Only $Job_Instance[2] is populated and it is like 14000 something Im not at work right now i will give a more detailed answer in the morning.Problem solved... I had to put Int() around each variable..
andybiochem Posted July 23, 2008 Posted July 23, 2008 Problem solved... I had to put Int() around each variable.. muttley ha ha Yup, I often find that I have to declare numbers coming from an array as numbers via Number() ....or as you found Int(). Look at this example.... $a = String(50) $b = String(100) If $a > $b Then MsgBox(0,"",$a & " is bigger than " & $B) ...if autoit thinks your numbers are in fact strings it seems to 'rank' them on a character-by-character basis. In the above case $a starts with 5, and $b starts with 1...thus, AutoIT thinks $a is bigger than $b. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
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