Jump to content

[SOLVED] Need little help with a syntax


Borje
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...