erebus Posted November 13, 2004 Posted November 13, 2004 I don't know if I use it right but check the following code please: $useme = StringSplit($useme, "-") If @error = 1 Then MsgBox(0, $app & " " & $ver, "Invalid String") Exit EndIf If Not IsDeclared("useme[5]") Then MsgBox(0, $app & " " & $ver, "Invalid String") Exit EndIf The idea is to check if the fifth splitted string is declared (so as to be sure that the string is of the correct form). What is wrong?
SlimShady Posted November 13, 2004 Posted November 13, 2004 This should work: $useme = StringSplit($useme, "-") If @error = 1 Then MsgBox(0, $app & " " & $ver, "Invalid String") Exit EndIf If Not IsDeclared($useme[5]) Then MsgBox(0, $app & " " & $ver, "Invalid String") Exit EndIf
erebus Posted November 13, 2004 Author Posted November 13, 2004 (edited) Unfortunately not... Tried with: If Not IsDeclared($useme[5]) Then MsgBox(0, $app & " " & $ver, "Invalid String") MsgBox(0, "", $useme[5]) Exit EndIf ...to verify. Edited November 13, 2004 by erebus
SlimShady Posted November 13, 2004 Posted November 13, 2004 (edited) I don't understand what you want to accomplish. If you see the message boxes, it means that the variable name stored in $useme[5], is not declared. Do you want to declare the variable with the name stored in $useme[5]? If you say "yes" use this: $useme = StringSplit($useme, "-") If @error = 1 Then MsgBox(0, $app & " " & $ver, "Failed to split the string!") Exit EndIf If Not IsDeclared($useme[5]) Then MsgBox(0, $app & " " & $ver, "Variable is not declared." & @CRLF & _ "Just wanted to let you know.") Assign($useme[5], "");<-- This function will only work if you use the unstable version Exit EndIf Edited November 13, 2004 by SlimShady
erebus Posted November 13, 2004 Author Posted November 13, 2004 (edited) Ok let me explain it better. - I want to split a string into 5 vars. - If the fifth (AND not the 6th) var exists means that the input string format is correct (xxx-xxx-xxx-xxx-xxx). If I put a condition like "If $useme[5] = "" Then...", it leads to an error when the $useme[5] variable does not exist (and the initial string format is incorrect). That is I want the IsDeclared function. However when I use the "If not IsDeclared($useme[5])" condition, it always considers the $useme[5] as not declared (even if it is created from the array and has a string assigned). I hope this is clear now :/ Thank you for your time.. P.S. I _do_ use the latest unstable. Edited November 13, 2004 by erebus
Administrators Jon Posted November 13, 2004 Administrators Posted November 13, 2004 Ok let me explain it better.- I want to split a string into 5 vars.- If the fifth (AND not the 6th) var exists means that the input string format is correct (xxx-xxx-xxx-xxx-xxx).If I put a condition like "If $useme[5] = "" Then...", it leads to an error when the $useme[5] variable does not exist (and the initial string format is incorrect). That is I want the IsDeclared function.However when I use the "If not IsDeclared($useme[5])" condition, it always considers the $useme[5] as not declared (even if it is created from the array and has a string assigned).I hope this is clear now :/Thank you for your time..P.S. I _do_ use the latest unstable.Just check the count that StringSplit sets up ( element [0] ) - If the count is less than 5 then the 5th bit is missing.
erebus Posted November 13, 2004 Author Posted November 13, 2004 Just check the count that StringSplit sets up ( element [0] ) - If the count is less than 5 then the 5th bit is missing.Doh... What If I tell you that I had completely forgotten element's[0] feature? Thanks a lot Jon, that was exactly what I needed.
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