Page 1 of 1

Local variable or ClearVariables?

PostPosted: Sun Jul 28, 2013 5:33 am
by reinier maliepaard
Hello,
With DefineVar you can make your Neobook variable local. That means (see Helpfile): "The variable exists only while the current script is executing. When the current script ends, the variable is automatically deleted." With ClearVariables you can clear a variable from memory at the end of a script. But what method should we prefer?
.
I did a quick test between DefineVar+Local and ClearVariables: see below. It appears that subroutineB with ClearVariables is faster. In use of resources, I think subroutineB is also better (I'm not 100% sure).
.
In addition:
ClearVariables "[MM1],[MM2],[MM3],[MM4],[MM5],[MM6]" is a bit more efficient than
.
ClearVariables "[MM1]"
ClearVariables "[MM2]"
ClearVariables "[MM3]"
ClearVariables "[MM4]"
ClearVariables "[MM5]"
ClearVariables "[MM6]"
.
So, if my point of view is valid (your comment is highly appreciated), ClearVariables should be prefered above the DefineVar+Local.
.
Regards,
Reinier

Code: Select all
.............................................
.properties of a PushButton
.............................................
SetVar "[start]" "[second]"
Loop "1" "1000" "[nloop]"
. GoSub "subroutineA"
 GoSub "subroutineB"
EndLoop
SetVar "[end]" "[second]"
Alertbox "Result" "1: [start]||2: [end]"
.............................................
:subroutineA
.............................................
DefineVar "[MM1]" "String" "" "Local" ""
DefineVar "[MM2]" "String" "" "Local" ""
DefineVar "[MM3]" "String" "" "Local" ""
DefineVar "[MM4]" "String" "" "Local" ""
DefineVar "[MM5]" "String" "" "Local" ""
DefineVar "[MM6]" "String" "" "Local" ""
.some operation
FileExists "[PubDir]test1.txt" "[MM1]"
FileExists "[PubDir]test2.txt" "[MM2]"
FileExists "[PubDir]test3.txt" "[MM3]"
FileExists "[PubDir]test4.txt" "[MM4]"
FileExists "[PubDir]test5.txt" "[MM5]"
FileExists "[PubDir]test6.txt" "[MM6]"
.or
.Math "10.4-(2.3*255.3/7.1)" "2" "[MM1]"
.Math "10.5-(2.4*255.4/7.2)" "2" "[MM2]"
.Math "10.6-(2.5*255.5/7.3)" "2" "[MM3]"
.Math "10.7-(2.6*255.6/7.4)" "2" "[MM4]"
.Math "10.8-(2.7*255.7/7.5)" "2" "[MM5]"
.Math "10.9-(2.8*255.8/7.6)" "2" "[MM6]"
Return
.............................................
:subroutineB
.............................................
.some operation
FileExists "[PubDir]test1.txt" "[MM1]"
FileExists "[PubDir]test2.txt" "[MM2]"
FileExists "[PubDir]test3.txt" "[MM3]"
FileExists "[PubDir]test4.txt" "[MM4]"
FileExists "[PubDir]test5.txt" "[MM5]"
FileExists "[PubDir]test6.txt" "[MM6]"
.or
.Math "10.4-(2.3*255.3/7.1)" "2" "[MM1]"
.Math "10.5-(2.4*255.4/7.2)" "2" "[MM2]"
.Math "10.6-(2.5*255.5/7.3)" "2" "[MM3]"
.Math "10.7-(2.6*255.6/7.4)" "2" "[MM4]"
.Math "10.8-(2.7*255.7/7.5)" "2" "[MM5]"
.Math "10.9-(2.8*255.8/7.6)" "2" "[MM6]"

ClearVariables "[MM1],[MM2],[MM3],[MM4],[MM5],[MM6]"
Return
.............................................