Jump to content
Sign in to follow this  
Borje

[SOLVED] Need little help with a syntax

Recommended Posts

Borje

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 by Borje

Share this post


Link to post
Share on other sites
Spiff59

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 by Spiff59

Share this post


Link to post
Share on other sites
Varian

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 by Varian

Share this post


Link to post
Share on other sites
Borje

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?

Share this post


Link to post
Share on other sites
Varian

Do you mean like a GOTO command? This is a small piece of a larger script?

Share this post


Link to post
Share on other sites
Varian

No, not in AutoIT. But if you give an example, we could figure out how to get that done

Share this post


Link to post
Share on other sites
Spiff59

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.

Share this post


Link to post
Share on other sites
Borje

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

Share this post


Link to post
Share on other sites
Varian

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?

Share this post


Link to post
Share on other sites
Borje

Thank you Varian yes you give me the answer of my question thanks again...

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.