Sign in to follow this  
Followers 0
Groumphy

A function in a function ?

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I've a small question... This is not a problem (ouf !).

If I use Javascript... I can write in my JS file a function in a function.

Sample (not tested only for fun) :

function chiffre() { 
    var xxx; 
    xxx = prompt('Number \? 0 to 10 \?', '0');
    if (xxx > 10) { function stop() { alert('Incorrect'); }; stop(); }
    else { function superieure(){ alert('Good : ' + xxx); }; superieure(); } }

But if I use the same idea for AutoIt :

Func msg()
    Dim $s_box 
    $s_box = MsgBox(4+64, "Test", "This is a test of a function in an other function")
    If $s_box = 6 Then
    Func myPing() 
        Dim $u_var 
        $u_var = Ping("begroumphy",250)
        If $var Then; also possible:  If @error = 0 Then ...
            Msgbox(0,"Status","Online, roundtrip was:" & $u_var)
        Else
            Msgbox(0,"Status","An error occured with number: " & @error)
        EndIf
    EndFunc
        myPing()
    Else
    MsgBox(0+64, "Test", "Exit of script", 3)
    EndIf
EndFunc
msg()
Exit

This doesn't work ! Can you inform me why a function in a function gives errors ?

Edited by Groumphy

----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can't have a function in a function... I don't know why

Not Tested..

msg()
Func msg();==>msg
    Dim $s_box
    $s_box = MsgBox(4 + 64, "Test", "This is a test of a function in an other function")
    If $s_box = 6 Then
        myPing ()
    Else
        MsgBox(0 + 64, "Test", "Exit of script", 3)
    EndIf
EndFunc   
Func myPing ();==>myPing
    Dim $u_var
    $u_var = Ping("bexbrusselaers", 250)
    If $var Then; also possible:  If @error = 0 Then ...
        MsgBox(0, "Status", "Online, roundtrip was:" & $u_var)
    Else
        MsgBox(0, "Status", "An error occured with number: " & @error)
    EndIf
EndFunc
Edited by Kogmedia

[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search

Share this post


Link to post
Share on other sites

Ok... It is a fact !

But why can't that function? I declare my function, following his call, but it does not put an error to me on the function but well on the "if" Thus syntax is correct, but the call is not execute (done)...


----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites

From the help file:

"Note that function declarations cannot appear inside other function declarations. "

And why would you want to? It's an ugly practice which makes code messy and hard to follow.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Oops !

Hum, sorry, I don't read the "help topics" about the Func !

I'm confused...

Big sorry, and big thanks for your answer...


----------------------GroumphyMore information about me [Fr]

Share this post


Link to post
Share on other sites

@Kogmedia >> Ok, for your small script (this form was know... :whistle: ) but that was for a direct include... :lmao:


----------------------GroumphyMore information about me [Fr]

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