Sign in to follow this  
Followers 0
Derak

Func Name with Array?

8 posts in this topic

#1 ·  Posted (edited)

Hey,

I've gone tired of repeating the same lines all over again but with changing one or two numbers. So, I thought of using arrays. The problem now is that it concerns Func names as well. Then, sadly, it appeared to me that I can't have an array, "[number]", within a function name. :D

Here is the code before Array:

Case $Button_Ans_23_5
            Ans_23_5()
            
        Case $Button_Ans_23_7
            Ans_23_7()
            
        Case $Button_Ans_23_9
            Ans_23_9()
            
        Case $Button_Ans_23_15
            Ans_23_15()
            
        Case $Button_Ans_23_18
            Ans_23_18()
            
        Case $Button_Ans_23_28
            Ans_23_28()
            
        Case $Button_Ans_23_29
            Ans_23_29()
            
        Case $Button_Ans_23_35
            Ans_23_35()
            
        Case $Button_Ans_23_37
            Ans_23_37()

And since I can't have Case inside For, I had to do this after Arraying:

Dim $E[$Nu]

$E[0] = 7
$E[1] = 9
$E[2] = 15
$E[3] = 18
$E[4] = 28

$E[5] = 5
$E[6] = 35

$E[7] = 29
$E[8] = 37
$E[9] = 56

    For $b = 0 to ($Nu - 1)
        If $nMsg = $Button_Ans_23_[$E[$b]] Then
            Ans_23_[$E[$b]]()
        EndIf
    Next

Yeah, this $Button_Ans_23_[$E[$b]] is fine. My problem is with this Ans_23_[$E[$b]]().

I can't have an array in a function name. :D

So, any suggestions? :o

Edited by Derak

[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe you're looking for the Call?

Call(Ans_23_[$E[$b]])

Edit: I don't know if it makes sense to call it this way because it's evaluated to different string. I'd go with Eval and without array. Anyway, after a second thought, I think it should be like this:

Call('Ans_23_' & $E[$b])

Edited by Authenticity

Share this post


Link to post
Share on other sites

Maybe you're looking for the Call?

Call(Ans_23_[$E[$b]])

Edit: I don't know if it makes sense to call it this way because it's evaluated to different string. I'd go with Eval and without array. Anyway, after a second thought, I think it should be like this:

Call('Ans_23_' & $E[$b])

Wow, you're right about using Call! :o

This Call('Ans_23_' & $E[$b]) is working fine. It's exactly what I was looking for.

I've always wondered about the difference between using Call("function") and using just function().

But now I think that "it's for using Arrays in function name" is one of the reasons.

(Not sure if their are other reasons :D)

Thanx for your help, Authenticity :D


[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Have you even thought about on-event-mode?

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

omg... :D

Using Call I get this error when I try to press the same button for a second time or if I try to press another button after pressing one:

Subscript used with non-Array variable.:

Call("Ans_23_" & $E[$b])

Call("Ans_23_" & $E^ ERROR

I can press any button I want as long as it's the first time I do it. But if it was after another button then that error appears.

I think it has something to do with the fact that Call does not return to where it was called like using function() does. (something like that)

So, Call have failed me.

Have you even thought about on-event-mode?

8)

Nope, I've almost forget that one.

Wow, OnEvent Mode works better than Call for me! :D

I've just tried it now and unlike Call I can press the button as many times as I want with no annoying subscripts bla bla bla errors. ^^

I've never considered or used OnEvent Mode before because it need a lot of work. I have to make Func for even $GUI_EVENT_CLOSE now and I have 17 forms in just one script.

Not to mention that the other insignificant buttons needs to be Funced as well now. I think that I put them all in one Func and just do Select Case @GUI_CtrlId =.... EndSelect. :o

Anyway, thanx for helping, Valuater. ^^

Edited by Derak

[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

Share this post


Link to post
Share on other sites

New Error! :D

I've finished my script and everything is working perfectly in it. Now, the Obfuscator is showing this error:

-### Obfuscation Error: Found GUICtrlSetOnEvent() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.

>### current Func: Main Script

Warning for line:GUICtrlSetOnEvent($Button_Ans_23_[$b], "Ans_23_" & $E[$b])

-#########################################################

-#### Obfuscator Found 1 Error(s)!!!! This means your script could have problems running properly.

-#########################################################

When I press "continue anyway" and then try to launch the compiled obfuscated script, the "Line -1" error shows up.

So, any suggestions?

I really need to protect my source, you know. ^^


[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

Share this post


Link to post
Share on other sites

New Error! :o

I've finished my script and everything is working perfectly in it. Now, the Obfuscator is showing this error:

When I press "continue anyway" and then try to launch the compiled obfuscated script, the "Line -1" error shows up.

So, any suggestions?

I really need to protect my source, you know. ^^

If you have stopped using Exectue() or Call() in favor of event mode, why is the second parameter still formatted like that? A simpler solution would be to set all the buttons to the same event handler, which can check the button text, or look it up in an array with @GUI_CTRLID.

:D


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

#8 ·  Posted (edited)

When I press "continue anyway" and then try to launch the compiled obfuscated script, the "Line -1" error shows up.

So, any suggestions?

I really need to protect my source, you know. ^^

If you have stopped using Exectue() or Call() in favor of event mode, why is the second parameter still formatted like that? A simpler solution would be to set all the buttons to the same event handler, which can check the button text, or look it up in an array with @GUI_CTRLID.

:D

I do need to format it like this "Ans_23_" & $E[$b] because I have different Funcs to go to here.

Func Ans_23_4
 Func Ans_23_7
 Func Ans_23_9
 Func Ans_23_10
 Func Ans_23_16
 Func Ans_23_18
 Func Ans_23_28
.
.
.

Even If I set all the buttons to one Event handler like this:

For $b = 0 To ($Nu - 1)
    GUICtrlSetOnEvent($Button_Ans_23_[$b], "Ans")
Next

And then for Func Ans:

Func Ans()
    For $k = 0 To ($Nu - 1)
        If @GUI_CtrlId = $Button_Ans_23_[$b] Then 
            Call("Ans_23_" & $E[$b])
        EndIf
    Next
EndFunc

I will get back to Call again. >.<

Is that what you meant by "which can check the button text, or look it up in an array with @GUI_CTRLID." ?

:o

Edited by Derak

[quote]#include <AutoIt.au3> [indent]$Nothing = Impossible[/quote] [/indent]

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