notsure Posted October 15, 2009 Share Posted October 15, 2009 Hi, i'm trying to use the Stringsplit function. It looks like this; local $AssignArray[7] $assignarray = stringsplit($ircdata, " ") if $assignarray[0] > 2 Then tcpsend($remoteserver, $assignarray[1]) exit EndIf $columnNames[7]="" Dim $NewGuest[8] $NewGuest[0]="" $NewGuest[1]=$assignarray[1] $NewGuest[2]=$assignarray[2] I'm not sure how many times a "space" (split delimiter) will occur in the string i'm trying to split. If its less than 2 the program crashes like this; (230) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $NewGuest[2]=$assignarray[2] $NewGuest[2]=^ ERROR I know thats coz the number [2] is not used in the array coz the occurence of a "space" is only once. Even if i try to avoid that piece of code with an "exit" fails. SCITE gives me an error before the code is even there? Anyone how to make sure it doesn't crash this way? Thanks in advance! Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 15, 2009 Share Posted October 15, 2009 You already have the answer and used it with "if $assignarray[0] > 2 Then". The stuff about $NewGuest needs to be inside that If/EndIf also, or you need to repeat that test around that part too. 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 Link to comment Share on other sites More sharing options...
notsure Posted October 16, 2009 Author Share Posted October 16, 2009 You already have the answer and used it with "if $assignarray[0] > 2 Then". The stuff about $NewGuest needs to be inside that If/EndIf also, or you need to repeat that test around that part too. Seems plausible but whats the reason why the code below does not give that error ? #include<array.au3> local $newguest[10] local $ircdata = "hi i am a string" $ircdata = stringsplit($ircdata," ") $newguest[0]= $ircdata[0] $newguest[1]= $ircdata[1] $newguest[2]= $ircdata[2] $newguest[3]= $ircdata[3] $newguest[4]= $ircdata[4] $newguest[5]= $ircdata[5] exit $newguest[6]= $ircdata[6] It's the same idea but this code does not give the error becoz i "exit" first, but the other code where i also FIRST "exit" does give the error. Im confused :S Link to comment Share on other sites More sharing options...
Authenticity Posted October 16, 2009 Share Posted October 16, 2009 Logical run-time errors are not posted while checking for syntactical correctness of your script but while executing the specific statement. Even though you are positive that the "if $assignarray[0] > 2 Then" condition is satisfied, the Exit statement should be executed for sure. By the way, the return value of StringSplit() is an array type, you don't need to declare a variable is an array because it'll be so when the function returns. Link to comment Share on other sites More sharing options...
SimonWebstation Posted October 16, 2009 Share Posted October 16, 2009 For this problem you need for and next look it up in the help Example Dim $NewGuest[$assignarray[0]] $NewGuest[0]="" For $i = 1 To $assignarray[0] $NewGuest[$i]=$assignarray[$i] Next mfg. SimonMany of my answers are translated of google, because I'am from Germany Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 16, 2009 Share Posted October 16, 2009 (edited) ...but the other code where i also FIRST "exit" does give the error. You don't enter the IF clause because $assignarray[0] is not > 2, so the exit doesn't happen. Perhaps you meant to use: If $assignarray[0] < 2 Then Edited October 16, 2009 by PsaltyDS 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 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