Sign in to follow this  
Followers 0
moonglow

Help - eval() again

10 posts in this topic

Hi,

my second try to find some help :-)

Has anybody any clue why the first statement does not work like the second one?

Dim $aTest[1]
$aTest[0] = "Some string"
$aOtherTest = "Some other string"

$string = "aTest[0]"
MsgBox(0,"aTest array",eval($string))

$string = "aOtherTest"
MsgBox(0,"aTest variable",eval($string))

I would expect both to show the defined strings.

Thank a lot for your patience

Share this post


Link to post
Share on other sites



Dim $aTest[1]
$aTest[0] = "Some string"
$aOtherTest = "Some other string"
$string = "aTest[0]"
MsgBox(0,"aTest array",eval($string))
$string = "aOtherTest"
MsgBox(0,"aTest variable",eval($string))
You have left out the "$" dollar signs in your two statements $string = "aTest[0]" and $string = "aOtherTest"

That might help... :o


...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

You have left out the "$" dollar signs in your two statements $string = "aTest[0]" and $string = "aOtherTest"

That might help... :o

No, I don´t think that´s the point. But I still don´t now, why the first won´t run. :geek:

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Not quite sure what you would need Eval for with an array anyway to be quite honest... Had you tried something like this?

$aTest1 = "Some string"
$aTest2 = "Some string2"
$aTest3 = "Some string3"

For $i = 1 To 3
    $string = Eval("aTest" & $i)
    MsgBox(0,"aTest array",$string)
Next


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You have left out the "$" dollar signs in your two statements $string = "aTest[0]" and $string = "aOtherTest"

That might help... :o

That's not the point, if you put the '$' in front, eval won't work :-)

Thanks anyway!

Share this post


Link to post
Share on other sites

Not quite sure what you would need Eval for with an array anyway to be quite honest... Had you tried something like this?

$aTest1 = "Some string"
$aTest2 = "Some string2"
$aTest3 = "Some string3"

For $i = 1 To 3
    $string = Eval("aTest" & $i)
    MsgBox(0,"aTest array",$string)
Next
Hi, thanks a lot for your response,

that would work, if I knew how many strings there will be, but I try to build a function that will take an array of variable elements which define text and positions for the GUICtrlCreateXXX() function.

I'll upload a small example which shows why I do it that way (and of course because I don't know any better way :"> )

Here you can see the bit where it is used: I have some arrays filled with information read out of the registry and the value hold by the specific arrayelement should be shown there.

If $aInput[$i][$field] == "Input" Then
    if StringLeft($aFields[$i][$text],1) == "$" Then
        $result = assign($aInput[$i][$field] & '_' & $i,GUICtrlCreateInput(eval(StringRight($aInput[$i][$text],StringLen($aInput[$i][$text])-1)), $aDim[$aInput[$i][$pos]][$Left], $aDim[$aInput[$i][$pos]][$Top]*$j*$aDim[$aInput[$i][$pos]][$Factor], $aDim[$aInput[$i][$pos]][$Width], $aDim[$aInput[$i][$pos]][$Height]+$aConfig[0][$Height]))
    Else
        $result = assign($aInput[$i][$field] & '_' & $i,GUICtrlCreateInput($aInput[$i][$text], $aDim[$aInput[$i][$pos]][$Left], $aDim[$aInput[$i][$pos]][$Top]*$j*$aDim[$aInput[$i][$pos]][$Factor], $aDim[$aInput[$i][$pos]][$Width], $aDim[$aInput[$i][$pos]][$Height]+$aConfig[0][$Height]))
    EndIf
EndIf

(see attached file)

Share this post


Link to post
Share on other sites

Well first thing, nice UDF on the 2 dim...

2nd thing, damn your code gives me a headache just to look at :o

I guess my biggest question is... why not just use the Array that is defined with that element? Or am I completely missing the jest of this?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This works:

Dim $aTest[1]
$aTest[0] = "Some string"
$aOtherTest = "Some other string"

$string = "$aTest[0]"
MsgBox(0,"aTest array",Execute($string))

$string = "$aOtherTest"
MsgBox(0,"aTest variable",Execute($string))

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

Well first thing, nice UDF on the 2 dim...

2nd thing, damn your code gives me a headache just to look at :o

I guess my biggest question is... why not just use the Array that is defined with that element? Or am I completely missing the jest of this?

Hi,

thanks, but this UDF is not my one, the _ArrayCreateTwoDim was written by Dan Colón, I found it when starting with my research.

And sorry for the headache, I know it's hardly what you would call easy readable, but hopefully it will evolve into something usable. I often cursed the fact, that after creating a small GUI it turned out to be missing one ore more things, so I had to add them manually. Not that big a feat, but it was always a pain to edit all the coordinates of the following GUIcontrols after inserting the missing one (even more so, if you had to do it twice or more times). So I thought it would be nice if it was equal where you insert it using calculated coordinates. At this time it is only usefull if the GUI isn't to complicated, say you have 2 or more columns of labels, input, checkboxes etc. starting at the same position. Given a bit more time I'll try to enhance it, maybe it could be included into one of those GUIbuilder tools (they are great to start with!).

Share this post


Link to post
Share on other sites

This works:

Dim $aTest[1]
$aTest[0] = "Some string"
$aOtherTest = "Some other string"

$string = "$aTest[0]"
MsgBox(0,"aTest array",Execute($string))

$string = "$aOtherTest"
MsgBox(0,"aTest variable",Execute($string))
Thanks a lot man, that seems to solve my problem. I had tried it before, but it didn't work because i made the mistake to discard the $ character in front like it has to be done in eval (stupid me, didn't look enough at the example)

So now I'll go on try it in my real prog :o

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0