bob51zhang Posted February 4, 2017 Share Posted February 4, 2017 Hey everyone, so before you shoot me with how I didn't do autoIT syntax correctly, I come from a Java background, and I'd love to learn. I'm having problems passing an Arrays by reference. Func numStar(Const ByRef $Array) For $i = 1 To UBound($Array) If $Array[$i] == "*" Then $numStar += 1 EndIf Next ;~ MsgBox(0, "JIM LENGTH", UBound($Array)) ;~ _ArrayDisplay($arr) ;~ For $i = 1 To UBound($Array) ;~ If (String($Array[$i]) == "*") Then ;~ $numStar += 1 ;~ EndIf ;~ Next MsgBox(0, "JJ", $numStar) EndFunc ;==>numStar Gives me the error 0"F:\Temp\test.au3" (58) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If $Array[$i] == "*" Then If ^ ERROR $Array: Single character, string array The function is basically looking for the number of stars in the array. Full code: http://pastebin.com/dDnuc0zM Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 4, 2017 Share Posted February 4, 2017 I won't tell you why it's breaking but I will tell you a great way to debug. Use _ArrayDisplay($Array) in your function call and on each iteration in the for loop, print $i to see it's value. You'll figure it out Also, you can use StringSplit to split a string into an array, each character in an index. _ArrayDisplay(StringSplit("Example Split Into Characters", "", $STR_NOCOUNT)) Link to comment Share on other sites More sharing options...
dmob Posted February 4, 2017 Share Posted February 4, 2017 Wild guess... you probably need: For $i = 1 To UBound($Array) - 1 If $Array[$i] == "*" Then $numStar += 1 EndIf Next Link to comment Share on other sites More sharing options...
mikell Posted February 4, 2017 Share Posted February 4, 2017 I'd rather say For $i = 0 To UBound($Array) - 1 Link to comment Share on other sites More sharing options...
Danyfirex Posted February 4, 2017 Share Posted February 4, 2017 Also: Local $Elements = ["A", "*", "X", "-", "*"] Local $numStar = 0 For $Element In $Elements If $Element == "*" Then $numStar += 1 Next Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut 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