XInFisk Posted January 21, 2008 Share Posted January 21, 2008 (edited) Hey. I've been trying to figure out, how to check if an array exists. Here's an ex. of my script. $cmdresread = GUICtrlRead($cmd) $cmdres = StringSplit($cmdresread, ",") If $cmdres[1] = ".hps" Then _hp($cmdres[2], $cmdres[3]) EndIf Func _hp($v = 0, $t = 0) If $v = 0 Then $hps = _FileCountLines(@Scriptdir & "\Console\Includes\hps.txt") _ConsoleWrite("DebugList 1") For $i = 0 to $hps $writehp = FileReadLine(@Scriptdir & "\Console\Includes\hps.txt", $i) GUICtrlSetData($Console, GUICtrlRead($Console) & @CRLF & $i & " " & $writehp) Next ElseIf $v = "start" Then _ConsoleWrite("Debug 1") If $t = 0 Then _ConsoleWrite("We got a error, dude :(") Else _ConsoleWrite("Debug 2") $hptoopen = FileReadLine(@SCRIPTDIR & "\Console\Includes\hps.txt", $t) _DosStart($hptoopen) EndIf EndIf EndFunc This works when i write ex. .hps,start,5 . But when i just write .hps, it wants to give the info from $cmdres[2] and $cmdres[3] to the func _hp. But those arrays do not exist. I've no idea how to make it check if it exists, because even when i just write it in the script, it fails. Like this: If $cmdres[2] = "" Then ;script ;bla bla Else ;script ;bla bla EndIf Can anyone help me out? It'd be a great help! Edit: Is this even possible? Regards Fisk Edited January 21, 2008 by XInFisk Link to comment Share on other sites More sharing options...
DW1 Posted January 21, 2008 Share Posted January 21, 2008 IsArray() AutoIt3 Online Help Link to comment Share on other sites More sharing options...
XInFisk Posted January 21, 2008 Author Share Posted January 21, 2008 IsArray()Thank you, but please write my post first. IsArray() only checks if a array exists, like $cmd. I need to check if $cmdres[2], $cmdres[3] and so on, if they exists. But please correct me, if i'm wrong. Regards Fisk Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted January 21, 2008 Share Posted January 21, 2008 Thank you, but please write my post first. IsArray() only checks if a array exists, like $cmd. I need to check if $cmdres[2], $cmdres[3] and so on, if they exists. But please correct me, if i'm wrong. Regards Fisk Check out Ubound. Link to comment Share on other sites More sharing options...
Malkey Posted January 22, 2008 Share Posted January 22, 2008 Hi there,This post caught my eye. XInFisk Asked, "I've been trying to figure out, how to check if an array exists."Then, in reply to danwili XInFisk wrote, "IsArray() only checks if a array exists""Strange, I thought. That was the original question.Then I saw "I need to check if $cmdres[2], $cmdres[3] and so on, if they exists""Ah! He wants to see if the contents of the array exists"Then I saw"If $cmdres[2] = "" Then"He's checked the contents.What the?Curiosity got the better of me. What is he asking?So I took XInFisk advise and read his post.$cmdres = StringSplit($cmdresread, ",")" Ah! you want to know the size of an array"Ubound "Yer, right answer.That will work"Then I thought (I do a lot of thinking )The art of problem solving is asking the right question.I left the forum.It stuck in my brain.The actual problem here is StringSplit($cmdresread, ",").If there are not three commas or more in $cmdresread, then $cmdresread[3] won't exist.As a test ,I wrote $cmdresread1 = "zero, one, two, three"$cmdresread2 = "zero, one, two"MsgBox(0,"zero, one, two, three",StringInStr($cmdresread1, ",", 0, 3))MsgBox(0,"zero, one, two",StringInStr($cmdresread2, ",", 0, 3))Note if there are only two commas or less, StringInStr($cmdresread2, ",", 0, 3)) will returns 0. So before you create the $cmdres array you could check if $cmdresread[3] is going to exist by checking if the third comma exists. ExampleIf StringInStr($cmdresread1, ",", 0, 3)) = 0 then or If StringInStr($cmdresread1, ",", 0, 3)) <> 0 thenJust a thought. Link to comment Share on other sites More sharing options...
Malkey Posted January 22, 2008 Share Posted January 22, 2008 I wrote If StringInStr($cmdresread1, ",", 0, 3)) = 0 then or If StringInStr($cmdresread1, ",", 0, 3)) <> 0 then I forgot StringSplit puts the number of strings returned in $cmdresread[0] so the above should be If StringInStr($cmdresread1, ",", 0, 2)) <> 0 then There only has to be two commas to get $cmdresread[3] Sorry 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