Groumphy Posted July 3, 2007 Share Posted July 3, 2007 (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 July 3, 2007 by Groumphy ----------------------GroumphyMore information about me [Fr] Link to comment Share on other sites More sharing options...
Kogmedia Posted July 3, 2007 Share Posted July 3, 2007 (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 July 3, 2007 by Kogmedia [font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search Link to comment Share on other sites More sharing options...
Groumphy Posted July 3, 2007 Author Share Posted July 3, 2007 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] Link to comment Share on other sites More sharing options...
Siao Posted July 3, 2007 Share Posted July 3, 2007 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 More sharing options...
Kogmedia Posted July 3, 2007 Share Posted July 3, 2007 From the help fileNote that function declarations cannot appear inside other function declarations. [font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search Link to comment Share on other sites More sharing options...
Groumphy Posted July 3, 2007 Author Share Posted July 3, 2007 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] Link to comment Share on other sites More sharing options...
Groumphy Posted July 3, 2007 Author Share Posted July 3, 2007 @Kogmedia >> Ok, for your small script (this form was know... ) but that was for a direct include... ----------------------GroumphyMore information about me [Fr] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now