glasglow Posted September 4, 2008 Share Posted September 4, 2008 (edited) $N = 12 Dim $x[$N] = [1,2,3,4,5,6,7,8,9,10,11,12] Dim $y[$N] = [24.91,29.65,29.40,28.90,27.80,25.74,23.76,23.83,26.12,26.86,27.01,25.36] Right now I am using this. And I would like to instead of writing out the variables, pull the variables out of either a text file or out of a csv file and instead of hardcoding the number of records I'd like to count the number of records as they are pulled out of the text or csv file. I've tried some csv parsers on here and they don't seem to be giving me what I need, and it seems when I try filereadtoarray it doesn't allow me to use the $x[$N] type variable. Any suggestions? lllllllllllllllllllllllllllllllllllllllll After a few minutes I got this: $N = 12 Dim $x _FileReadToArray("x.txt", $x) ;Dim $x[$N] = [1,2,3,4,5,6,7,8,9,10,11,12] Dim $y[$N] = [24.91,29.65,29.40,28.90,27.80,25.74,23.76,23.83,26.12,26.86,27.01,25.36] However I don't seem to be getting the same results in later calculations. Edited September 4, 2008 by glasglow Link to comment Share on other sites More sharing options...
Kerros Posted September 4, 2008 Share Posted September 4, 2008 (edited) When you use _Filereadtoarray you just need to have a declared variable it doesn't need to already be an array. Something like Local $file _filereadtoarray('yourfilegoeshere.txt',$file) Edit: Fixed code tag Edited September 4, 2008 by Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
glasglow Posted September 4, 2008 Author Share Posted September 4, 2008 (edited) It's really strange. If I use: $N = 7 Dim $x[$N] = [0,2,4,6,8,10,12] Dim $y[$N] = [2.1,5.0,9,12.6,17.3,21,24.7] And if I use this: $N = 7 Local $x _filereadtoarray('x.txt',$x) Local $y _filereadtoarray('y.txt',$y) Inside file x.txt I have: 0 2 4 6 8 10 12 And Inside file y.txt I have: 2.1 5.0 9, 12.6 17.3 21, 24.7 And I get different results. It does look like it is, or should be exactly the same... yes? Does the $x[$N] make it different or is it reading the text file in a different way? I seem to be missing something. Edited September 4, 2008 by glasglow Link to comment Share on other sites More sharing options...
Kerros Posted September 4, 2008 Share Posted September 4, 2008 The results are slightly different because of the way that _filereadtoarray is putting the data into the array versus manually filling in the array. From the Helpfile Remarks $aArray[0] will contain the number of records read into the array. If you ignore the first element, both arrays should be the same as long as the information in the text file is correct. Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
glasglow Posted September 4, 2008 Author Share Posted September 4, 2008 The results are slightly different because of the way that _filereadtoarray is putting the data into the array versus manually filling in the array.From the Helpfile If you ignore the first element, both arrays should be the same as long as the information in the text file is correct.I see.. very interesting. So when looping through I start with For $i = 1 to $N instead of $i = 0?Any other way around to "ignore" the first element? Link to comment Share on other sites More sharing options...
DW1 Posted September 4, 2008 Share Posted September 4, 2008 or use: For $i = 1 to UBound($array) - 1 AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 5, 2008 Share Posted September 5, 2008 For $i = 1 to $x[0] Link to comment Share on other sites More sharing options...
Kerros Posted September 5, 2008 Share Posted September 5, 2008 If you really want to get rid of the first element, use _arraydelete($x[0]), but yes, I normally use For $i = 1 to ubound($x) Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
DW1 Posted September 5, 2008 Share Posted September 5, 2008 This one will error when it hits the last value for $i since the UBound($x) will exceed the array dimensions by 1.. would need to be "UBound($x) - 1" I normally use For $i = 1 to ubound($x) This is a better solution: You already have the correct dimension size stored in $x[0] for looping For $i = 1 to $x[0] AutoIt3 Online Help Link to comment Share on other sites More sharing options...
glasglow Posted September 5, 2008 Author Share Posted September 5, 2008 Thank you guys for the help. What worked best for me in this case was: Local $x _filereadtoarray('x.txt',$x) Local $y _filereadtoarray('y.txt',$y) _arraydelete($x,0) _arraydelete($y,0) It completely cleared out the element put into the beginning by the _filereadtoarray Link to comment Share on other sites More sharing options...
Kerros Posted September 5, 2008 Share Posted September 5, 2008 This one will error when it hits the last value for $i since the UBound($x) will exceed the array dimensions by 1.. would need to be "UBound($x) - 1"Opps, yes that would cause a problem... that's what I get for trying to get a thought out quick. Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. 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