RyukShini Posted October 26, 2016 Posted October 26, 2016 (edited) Local $okay _FileReadToArray("Okay.txt", $okay) ; read the list of names to array For $i = 1 To UBound($okay) - 1 $Read = $okay[$i] If I run this and it goes to the end of Okay.txt it returns an error."Array variable has incorrect number of subscripts or subscript dimension range exceeded.:" so can I either exitloop if its run through the file or add some error checking that exitloop if array = empty? Thanks in advance. Edited October 26, 2016 by RyukShini
Jfish Posted October 26, 2016 Posted October 26, 2016 (edited) You should add a line to visualize your data to make sure it contains what you think it should. Otherwise, using ubound($array)-1 should make the loop run the correct number of times. Try this and look at the array, does it appear as you would expect it? Local $usrpwd _FileReadToArray("Okay.txt", $okay) ; read the list of names to array _arrayDisplay($okay); visualize data For $i = 1 To UBound($okay) - 1 $Read = $okay[$i] I tested this version which is almost the exact same as yours. The file contained three lines of data. I added debugging to error check the array creation and visualize it. It works fine. Maybe you could post your whole code? #include <Array.au3> #include <File.au3> global $okay Local $usrpwd $result=_FileReadToArray(@ScriptDir&"\tesfile.txt", $okay) ConsoleWrite($result&" error: "&@error&@crlf) _arrayDisplay($okay); visualize data For $i = 1 To UBound($okay) - 1 $Read = $okay[$i] ConsoleWrite($Read) Next Edited October 26, 2016 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
RyukShini Posted October 26, 2016 Author Posted October 26, 2016 6 minutes ago, Jfish said: You should add a line to visualize your data to make sure it contains what you think it should. Otherwise, using ubound($array)-1 should make the loop run the correct number of times. Try this and look at the array, does it appear as you would expect it? Also, note the difference in starting the loop at 0 vs 1. Local $okay _FileReadToArray("Okay.txt", $okay) ; read the list of names to array _arrayDisplay($okay); visualize data For $i = 1 To UBound($okay) - 1 $Read = $okay[$i] It seems to be correct?
Jfish Posted October 26, 2016 Posted October 26, 2016 (edited) Yes, try running my code where I put the results to the console in the for loop. You should see all four items from 1-4 in the console window of Scite. Edited October 26, 2016 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Juvigy Posted October 26, 2016 Posted October 26, 2016 @RyukShini And on which line of code do you get that error? The code in your first post seems correct (although not full)
RyukShini Posted October 26, 2016 Author Posted October 26, 2016 6 minutes ago, Jfish said: Yes, try running my code where I put the results to the console in the four loop. You should see all four items from 1-4 in the console window of Scite. Your code works, but I actually just found out why mine wasn't working. I needed a Continueloop in my code inside an IF statement. Now it works as intended and it continues the loop/stops correctly. Thanks a lot for the help
Jfish Posted October 26, 2016 Posted October 26, 2016 Ah, okay glad it is working but next time please include a full reproducer. That IF statement would have been good info ... Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
RyukShini Posted October 26, 2016 Author Posted October 26, 2016 7 minutes ago, Jfish said: Ah, okay glad it is working but next time please include a full reproducer. That IF statement would have been good info ... Alright sorry about that.
Bucione Posted October 26, 2016 Posted October 26, 2016 If you dont specify any flags to _FileReadToArray(), it will store the array count on index 0 by default. For $i = 1 to $okay[0] $Read = $okay[$i] Next ---------Arthur B
RyukShini Posted October 26, 2016 Author Posted October 26, 2016 2 minutes ago, Bucione said: If you dont specify any flags to _FileReadToArray(), it will store the array count on index 0 by default. For $i = 1 to $okay[0] $Read = $okay[$i] Next Alright thank you for making that clear.
antonioj84 Posted January 3, 2017 Posted January 3, 2017 On 26/10/2016 at 7:01 AM, RyukShini said: Your code works, but I actually just found out why mine wasn't working. I needed a Continueloop in my code inside an IF statement. Now it works as intended and it continues the loop/stops correctly. Thanks a lot for the help it would have been nice if you post your codes that work
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