Dragon5150 Posted October 22, 2008 Share Posted October 22, 2008 I am new to AutoIT but not to scripting and programing in general. When I used Winbatch there were two distinct type of user defined options, you had user defined functions and user defined subroutines. The major difference being a subroutine had access to all variables in the program and a function only could see its localized variables. Is there the same functionality in AutoIT? All I see are functions that can see all variables and do not terminate when the function is ended. Also, there was drop and dropwild commands to release variables in Winbatch, is there such a command in AutoIT? Any help would be greatly appreciated and I look forward to being able to contribute to this board. Adam Franks adam (dot) franks (at) gmail (dot) com Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 22, 2008 Share Posted October 22, 2008 I don't think there's a command to remove a variable but I could be wrong. Functions can see local and global variables but if a variable is simply Dim-ed (in my experience) the function can use them but the values are not held once the function is over. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Dragon5150 Posted October 22, 2008 Author Share Posted October 22, 2008 So let me try this, If I dim the variable outside of a function it will be globally available, but it I dim it inside the function it should not be accessible once the function has returned? Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 22, 2008 Share Posted October 22, 2008 i guess it was a bug in my coding at the time. Just tried an example and the function does indeed modify the variable outside itself but only if you use the same variable. So Dim $var, $one While 1 Sleep(250) _Func($var) MsgBox(0,"",$var) WEnd Func _Func($int) If $one = 0 Then $var = $int + 3 $one += 1 Endif EndFunc would show a message box with "3" as the text. If you were to do something like this Dim $var, $one While 1 Sleep(250) MsgBox(0,"",_Func($var)) WEnd Func _Func($int) Dim $ret If $one = 0 Then $ret = $int + 3 $one += 1 Endif Return $ret EndFunc It would return 3 once then return an empty string because the variable $ret is being redimmed with a value of 0. Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
Dragon5150 Posted October 22, 2008 Author Share Posted October 22, 2008 i guess it was a bug in my coding at the time. Just tried an example and the function does indeed modify the variable outside itself but only if you use the same variable. So Dim $var, $one While 1 Sleep(250) _Func($var) MsgBox(0,"",$var) WEnd Func _Func($int) If $one = 0 Then $var = $int + 3 $one += 1 Endif EndFunc would show a message box with "3" as the text. If you were to do something like this Dim $var, $one While 1 Sleep(250) MsgBox(0,"",_Func($var)) WEnd Func _Func($int) Dim $ret If $one = 0 Then $ret = $int + 3 $one += 1 Endif Return $ret EndFunc It would return 3 once then return an empty string because the variable $ret is being redimmed with a value of 0. Thanks for explaining it. I will have to go with using leading letters on the variables then to make sure I do not mess anything else up in the program, such as Funct _newfunct( $drg_newvar ) $drg_nextvar EndFunc the drg_ being the unique part of everything inside of that function. Link to comment Share on other sites More sharing options...
LarryDalooza Posted October 22, 2008 Share Posted October 22, 2008 In general I am not too picky about my local variable names... Func example($szIamLocal, $szIamLocalAlso) Local $varLocal ;... EndFuncoÝ÷ Ù»½êò¦'$Ë^v¦x Úö«¦åzÆ®¶sdvÆö&Âb33c¶uôÕ7V6ÅvF×uTäDU%44õ$ Lar. AutoIt has helped make me wealthy 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