JohnBailey Posted October 17, 2007 Share Posted October 17, 2007 The below code is an example of what I'm trying to do (note: the random function is just there for this example). Why does it say the variable does not exist when the Assign passes? For $i = 0 to 2 If Not Assign('htmlCaptureTab'&$i,Random(0,50,1)) Then MsgBox(0,'Var not created','At position '&$i) Else If IsDeclared(Eval('htmlCaptureTab'&$i)) Then ConsoleWrite('Variable Exists : '&'htmlCaptureTab'&$i &@LF) Else ConsoleWrite('Variable does NOT exist : '&'$htmlCaptureTab'&$i &@LF) EndIf EndIf Next A decision is a powerful thing Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 17, 2007 Share Posted October 17, 2007 The below code is an example of what I'm trying to do (note: the random function is just there for this example). Why does it say the variable does not exist when the Assign passes? For $i = 0 to 2 If Not Assign('htmlCaptureTab'&$i,Random(0,50,1)) Then MsgBox(0,'Var not created','At position '&$i) Else If IsDeclared(Eval('htmlCaptureTab'&$i)) Then ConsoleWrite('Variable Exists : '&'htmlCaptureTab'&$i &@LF) Else ConsoleWrite('Variable does NOT exist : '&'$htmlCaptureTab'&$i &@LF) EndIf EndIf Next Because you used Eval() in the wrong place: For $i = 0 To 2 If Not Assign('htmlCaptureTab' & $i, Random(0, 50, 1)) Then MsgBox(0, 'Var not created', 'At position ' & $i) Else If IsDeclared('htmlCaptureTab' & $i) Then ConsoleWrite('Variable Exists : ' & 'htmlCaptureTab' & $i & " = " & Eval('htmlCaptureTab' & $i) & @LF) Else ConsoleWrite('Variable does NOT exist : ' & '$htmlCaptureTab' & $i & " = " & Eval('htmlCaptureTab' & $i) & @LF) EndIf EndIf Next IsDeclared() wants the string name of the variable, not the contents of the variable. P.S. This doesn't address the fact that Assign() and Eval() are evil, and you should be doing this with an array instead... 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...
JohnBailey Posted October 17, 2007 Author Share Posted October 17, 2007 Because you used Eval() in the wrong place: For $i = 0 To 2 If Not Assign('htmlCaptureTab' & $i, Random(0, 50, 1)) Then MsgBox(0, 'Var not created', 'At position ' & $i) Else If IsDeclared('htmlCaptureTab' & $i) Then ConsoleWrite('Variable Exists : ' & 'htmlCaptureTab' & $i & " = " & Eval('htmlCaptureTab' & $i) & @LF) Else ConsoleWrite('Variable does NOT exist : ' & '$htmlCaptureTab' & $i & " = " & Eval('htmlCaptureTab' & $i) & @LF) EndIf EndIf Next IsDeclared() wants the string name of the variable, not the contents of the variable. P.S. This doesn't address the fact that Assign() and Eval() are evil, and you should be doing this with an array instead... HAHA thank you PsaltyDS! I just discovered that about IsDelcared() - it needing a string name. Good point about the array! :"> My actually code is MUCH longer and this was a VERY boiled down version. I was using Assign to store the variable id of a GUICtrl. However, as you said, I can do this with an array so THANK YOU and I'm a moron A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted October 17, 2007 Author Share Posted October 17, 2007 I used the array and it's working great, but I do have a huge problem http://www.autoitscript.com/forum/index.php?showtopic=55355 - More than one ctrl is removed/deleted WEIRD! A decision is a powerful thing 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