Jump to content

A function in a function ?


Recommended Posts

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]

Link to comment
Share on other sites

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
Link to comment
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"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...