Sign in to follow this  
Followers 0
meisandy

[Need more Help]Return a varible to use

10 posts in this topic

#1 ·  Posted (edited)

Hi,

I'm quite stuck, I don't know if this is possible and can't think of a work around so I came here!

I have 26 multi demsional array, obviously for each letter of the alphabet! And according to what the data that needs to be added to the array starts with, it determines what array it uses. For example: "Sally sits smartly" would go into $sArray etc.

Now, I've tried to make a function that returns the dimmed array varible (With & without qoutes) but obviously it's not an array with qoutes and without quotes, it just trys to return the value of the varible.

So, can anyone think of a way to get around this - because I really need to keep this function (if you get me)

DjAUTit

Edited by DjATUit

Share this post


Link to post
Share on other sites



Can you post your script, it will be more clear ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

This it what I've got so far:

Dim $files[1], $ATracks[1][6], $bTracks[1][6], $cTracks[1][6], $dTracks[1][6], $eTracks[1][6], $fTracks[1][6], $gTracks[1][6], $hTracks[1][6], $iTracks[1][6], $jTracks[1][6], $kTracks[1][6], $lTracks[1][6], $mTracks[1][6]
Dim $nTracks[1][6], $oTracks[1][6], $pTracks[1][6], $qTracks[1][6], $rTracks[1][6], $sTracks[1][6], $tTracks[1][6], $uTracks[1][6], $vTracks[1][6], $wTracks[1][6], $xTracks[1][6], $yTracks[1][6], $zTracks[1][6]
Func _ChooseAlphaArray($byName)
    $Letter = StringLeft($byName, 1)
    If StringCompare($Letter, "a") = 0 Then $Array = $ATracks
    If StringCompare($Letter, "b") = 0 Then $Array = $bTracks
    If StringCompare($Letter, "c") = 0 Then $Array = $cTracks
    If StringCompare($Letter, "d") = 0 Then Return "$dTracks"
    If StringCompare($Letter, "e") = 0 Then Return $eTracks
    If StringCompare($Letter, "f") = 0 Then Return $fTracks
    If StringCompare($Letter, "g") = 0 Then Return $gTracks
    If StringCompare($Letter, "h") = 0 Then Return $hTracks
    If StringCompare($Letter, "i") = 0 Then Return $iTracks
    If StringCompare($Letter, "j") = 0 Then Return $jTracks
    If StringCompare($Letter, "k") = 0 Then Return $kTracks
    If StringCompare($Letter, "l") = 0 Then Return $lTracks
    If StringCompare($Letter, "m") = 0 Then Return $mTracks
    If StringCompare($Letter, "n") = 0 Then Return $nTracks
    If StringCompare($Letter, "o") = 0 Then Return $oTracks
    If StringCompare($Letter, "p") = 0 Then Return $pTracks
    If StringCompare($Letter, "q") = 0 Then Return $qTracks
    If StringCompare($Letter, "r") = 0 Then Return $rTracks
    If StringCompare($Letter, "s") = 0 Then Global $Array = $sTracks
    If StringCompare($Letter, "t") = 0 Then Return $tTracks
    If StringCompare($Letter, "u") = 0 Then Return $uTracks
    If StringCompare($Letter, "v") = 0 Then Return $vTracks
    If StringCompare($Letter, "w") = 0 Then Return $wTracks
    If StringCompare($Letter, "x") = 0 Then Return $xTracks
    If StringCompare($Letter, "y") = 0 Then Return $yTracks
    If StringCompare($Letter, "z") = 0 Then Return $zTracks
EndFunc

Well, The function I'm trying to use - I'm guessing you can easily figure out how it's used (I assign the function to a varible and then use the varible in place of an array...)

Ive left it how I was testing it so you can see the different methods I've tried. kinda

Thanks in advance

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Generally, the need to do this means you have a very poorly designed script for starters, but:

Global $aTxt[3][3]
For $r = 0 To UBound($aTxt) - 1
    For $c = 0 To UBound($aTxt, 2) - 1
        $aTxt[$r][$c] = "Item " & $r & "-" & $c
    Next
Next
ConsoleWrite(Execute("$aTxt[1][1]") & @LF)

;)

Edit: Made it a 2D demo.

@DjATUit: You could just use a 3D array:

Dim $Tracks[26][1][6]

Also, while you can't give an array reference with indexes to Eval(), you can copy the entire array with it:

Func _ChooseAlphaArray($byName)
    $Letter = StringLeft($byName, 1)
    $Array = Eval($Letter & "Tracks")
EndFunc

:)

Edited 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

Share this post


Link to post
Share on other sites

PsaltyDS,

Firstly, the only reason I'm doing this is for speed, there could be millions of entries if I use just one array!

Secondly, your script/idea looks good but could you 'like' implement it into what I've got or something because I don't quite get you.

Share this post


Link to post
Share on other sites

OMG, thank you so much

I wish I new about Eval()two days ago!

Thanks, again

PS As soon as I can I'm going to give this board a massive donation (and AutoIT) beause all of you have helped me soo much!

Share this post


Link to post
Share on other sites

Before this post gets to old....

How can I add to an array using Eval()?

Because when I assign Eval to varible like :- $Eval = Eval($Letter & "Words") it just uses $Eval like an array (I think - it doesn't show up in the propper array)

And if I use it directly (i.e _ArrayAdd(Eval($Letter & "Words")....) ) it just sets an error (because of ByRef)

Please Help ASAP

???

Thanks

Share this post


Link to post
Share on other sites

Assign() and Eval() can only be used to COPY the array variable. No array functions can be done with them. Copy the array to a known temp variable with Eval(), operate on the temp, then copy it back with Assign():

Func _AddWordToLetterArray($sInput)
    Local $sLetter = StringLeft($sInput, 1)
    Local $aTemp = Eval($sLetter & "Word")
    _ArrayAdd($aTemp, $sInput)
    Assign($sLetter & "Word", $aTemp)
EndFunc

;)


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

Share this post


Link to post
Share on other sites

Thank you PsaltyDS and sorry for the slow reply.

As soon as I added assign to my script it worked!

So you helped me alot

Thanks

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