Borje Posted February 8, 2009 Share Posted February 8, 2009 (edited) My question is what to do if I want to jump to the beginning of the script again? Exaple if I run this siple script what must I do I not want to Exit the script I wamt to start it again after som delay? [Func StartVBS() Global $VBS="" $VBS=ObjCreate("MSScriptControl.ScriptControl") $VBS.Language="VBScript" EndFunc Func MonthName($mNum,$aBBv=False) Return $VBS.Eval("MonthName("&$mNum&","&$aBBv&")") EndFunc Func WeekDayName($wNum,$aBBv=False) Return $VBS.Eval("WeekDayName("&$wNum&","&$aBBv&")") EndFunc StartVBS() $TXT="Short Month Name "&MonthName(@Mon,True)&@crlf $TXT&="Short Week Name "&WeekDayName(@wDay,True)&@crlf $TXT&="Long Month Name "&MonthName(@Mon)&@crlf $TXT&="Long Week Name "&WeekDayName(@wDay)&@crlf msgbox(0,"VBS ScriptControl",$TXT) $VBS=0 Sleep (5000)] Edited February 8, 2009 by Borje Link to comment Share on other sites More sharing options...
Spiff59 Posted February 8, 2009 Share Posted February 8, 2009 (edited) Ya stick it all in a loop... ; INITIALIZATION ---------------------------------------------------------- HotKeySet("{ESC}", "Quit") Global $VBS="" ; MAIN LOOP --------------------------------------------------------------- While 1 StartVBS() $TXT="Short Month Name "&MonthName(@Mon,True)&@crlf $TXT&="Short Week Name "&WeekDayName(@wDay,True)&@crlf $TXT&="Long Month Name "&MonthName(@Mon)&@crlf $TXT&="Long Week Name "&WeekDayName(@wDay)&@crlf msgbox(0,"VBS ScriptControl",$TXT) $VBS="" Sleep (5000)] WEnd Exit ; FUNCTIONS --------------------------------------------------------------- Func StartVBS() $VBS=ObjCreate("MSScriptControl.ScriptControl") $VBS.Language="VBScript" EndFunc Func MonthName($mNum,$aBBv=False) Return $VBS.Eval("MonthName("&$mNum&","&$aBBv&")") EndFunc Func WeekDayName($wNum,$aBBv=False) Return $VBS.Eval("WeekDayName("&$wNum&","&$aBBv&")") EndFunc Func Quit() Exit EndFunc EDIT: I didn't really look at your code, just wrapped a loop around it. But, I agree with Varian about the declare. I updated my example with Varian's change. Also, I'm not sure what you're trying to do, but not sure you really need to re-execute ObjCreate over and over... Edited February 8, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
Varian Posted February 8, 2009 Share Posted February 8, 2009 (edited) Other than simple syntax errors and grooming (easier to see what's going on), this script works here. Global $Vbs ;It's usually better to declare Global variables outside of Function ;because if another call is made to it before it is defined, script ;will error out While 1 If IsObj($Vbs) Then $Vbs = ObjGet("", "MSScriptControl.ScriptControl") If @error Then StartVBS() Else StartVBS() ;call function to create your Object EndIf $Txt = "Short Month Name " & MonthName(@MON, True) & @CRLF $Txt &= "Short Week Name " & WeekDayName(@WDAY, True) & @CRLF $Txt &= "Long Month Name " & MonthName(@MON) & @CRLF $Txt &= "Long Week Name " & WeekDayName(@WDAY) & @CRLF MsgBox(0, "VBS ScriptControl", $Txt) Sleep(5000) WEnd Func StartVBS() $Vbs = ObjCreate("MSScriptControl.ScriptControl") If @error Then Exit ;make sure Object is created $Vbs.Language = "VBScript" EndFunc ;==>StartVBS Func MonthName($mNum, $aBBv = False) Return $Vbs.Eval("MonthName(" & $mNum & "," & $aBBv & ")") EndFunc ;==>MonthName Func WeekDayName($wNum, $aBBv = False) Return $Vbs.Eval("WeekDayName(" & $wNum & "," & $aBBv & ")") EndFunc ;==>WeekDayName EDIT: Forgot the Loop Edited February 8, 2009 by Varian Link to comment Share on other sites More sharing options...
Borje Posted February 8, 2009 Author Share Posted February 8, 2009 Thanks Spiff and Varian I try this examples.. Link to comment Share on other sites More sharing options...
Borje Posted February 8, 2009 Author Share Posted February 8, 2009 Thanks that works fine is that only way to do this is there not a command for this if I want to jump from one place to another place in the script? Link to comment Share on other sites More sharing options...
Varian Posted February 8, 2009 Share Posted February 8, 2009 Do you mean like a GOTO command? This is a small piece of a larger script? Link to comment Share on other sites More sharing options...
Borje Posted February 8, 2009 Author Share Posted February 8, 2009 Yes like a goto command.. Link to comment Share on other sites More sharing options...
Varian Posted February 8, 2009 Share Posted February 8, 2009 No, not in AutoIT. But if you give an example, we could figure out how to get that done Link to comment Share on other sites More sharing options...
Spiff59 Posted February 8, 2009 Share Posted February 8, 2009 Since you're ecexuting MSScriptControl every 5 seconds, you might find this more efficient... ; INITIALIZATION ---------------------------------------------------------- HotKeySet("{ESC}", "Quit") Global $VBS=ObjCreate("MSScriptControl.ScriptControl") $VBS.Language="VBScript" ; MAIN LOOP --------------------------------------------------------------- While 1 $TXT="Short Month Name "&MonthName(@Mon,True)&@crlf $TXT&="Short Week Name "&WeekDayName(@wDay,True)&@crlf $TXT&="Long Month Name "&MonthName(@Mon)&@crlf $TXT&="Long Week Name "&WeekDayName(@wDay)&@crlf ToolTip($TXT) Sleep (5000) ToolTip("") Sleep (50); delay just to make the tooltip flash, so you'll know it's updating WEnd Exit ; FUNCTIONS --------------------------------------------------------------- Func MonthName($mNum,$aBBv=False) Return $VBS.Eval("MonthName("&$mNum&","&$aBBv&")") EndFunc Func WeekDayName($wNum,$aBBv=False) Return $VBS.Eval("WeekDayName("&$wNum&","&$aBBv&")") EndFunc Func Quit() $VBS="" Exit EndFunc Although, since month and day hardly change every 5 seconds, I guess I have no idea what you're doing. Link to comment Share on other sites More sharing options...
Borje Posted February 8, 2009 Author Share Posted February 8, 2009 I try to explain little more If I have a script and running that after it running it closed what I want is to have hotkey when I stop or exit the the script if I not press esc I want the script run again from the beginning of code off the script until I press ESC to exit Link to comment Share on other sites More sharing options...
Varian Posted February 8, 2009 Share Posted February 8, 2009 If there is more code to the script, just put the "While 1" where you want the loop to begin and the "WEnd" where you want the loop to end, as we have done here. Spiff's code has already given you a the ESC hotkey to exit out of the script. Does that answer your question? Link to comment Share on other sites More sharing options...
Borje Posted February 8, 2009 Author Share Posted February 8, 2009 Thank you Varian yes you give me the answer of my question thanks again... 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