Sign in to follow this  
Followers 0
spikyoneuk

Something wrong...machine shutsdown regardless of Yes or No.

3 posts in this topic

Newb here to both scripting and AutoIT so please excuse the newbness.

Little bit of help please. I've written a script to log off of Sametime and if the user clicked Yes close down the machine however the script closes the machine regardless of whether Yes or No is clicked.

Where have I gone wrong?

MsgBox (4,"Shut Down", "Do you want to shut down the machine after logging off of S/T?", "", "",);Yes or No to shutting down the machine.

If 6 Then ; If it's a Yes

$logofftime = InputBox("Log Off", "How long until you want S/T to log off? Enter amount of time in milliseconds","","");Prompt to enter in the countdown in milliseconds until logoff. The number entered

;will be stored as variable $logofftime.

Sleep ($logofftime);Take the figure entered from the previous message and delay for that long.

WinActivate ("IBM Lotus Sametime Connect");Make the Sametime client active.

Sleep (500);Wait half a second.

Send ("!f");Type Alt+f to bring up the File menu.

Send ("{DOWN 4})");Move down the menu 4 places.

Sleep (500);Wait half a second.

Send ("{ENTER}");Press Enter on Log Out

Shutdown (8);Shutdown the machine.

Else;If it's a No

$logofftime = InputBox("Log Off", "How long until you want S/T to log off? Enter amount of time in milliseconds","","");Prompt to enter in the countdown in milliseconds until logoff. The number entered

;will be stored as variable $logofftime.

Sleep ($logofftime) ;Take the figure entered from the previous message and delay for that long.

WinActivate ("IBM Lotus Sametime Connect") ;Make the Sametime client active.

Sleep (500);Wait half a second.

Send ("!f") ;Type Alt+f to bring up the File menu.

Send ("{DOWN 4})");Move down the menu 4 places.

Sleep (500);Wait half a second.

Send ("{ENTER}") ;Press Enter on Log Out

EndIf

Share this post


Link to post
Share on other sites



spikyoneuk,

Firstly, your MsgBox syntax was wrong - the final {optional} parameters are numbers, so you should have used 0 not "". But as they are optional, best omit them altogether. >_<

Then to make your code work you need to get a result from the MsgBox and run some form of question code. Here are several options:

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
If $answer = 6 Then ; If it's a Yes
    ConsoleWrite("Yes" & @CRLF)
Else
    ConsoleWrite("No" & @CRLF)
EndIf

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
Select
    Case $answer = 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSelect

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
Switch $answer
    Case 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSwitch

If MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?") = 6 Then
    ConsoleWrite("Yes" & @CRLF)
Else
    ConsoleWrite("No" & @CRLF)
EndIf

; My personal favourite
Switch MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
    Case 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSwitch

Ask if anything is unclear.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

spikyoneuk,

Firstly, your MsgBox syntax was wrong - the final {optional} parameters are numbers, so you should have used 0 not "". But as they are optional, best omit them altogether. >_<

Then to make your code work you need to get a result from the MsgBox and run some form of question code. Here are several options:

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
If $answer = 6 Then ; If it's a Yes
    ConsoleWrite("Yes" & @CRLF)
Else
    ConsoleWrite("No" & @CRLF)
EndIf

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
Select
    Case $answer = 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSelect

$answer = MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
Switch $answer
    Case 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSwitch

If MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?") = 6 Then
    ConsoleWrite("Yes" & @CRLF)
Else
    ConsoleWrite("No" & @CRLF)
EndIf

; My personal favourite
Switch MsgBox(4, "Shut Down", "Do you want to shut down the machine after logging off of S/T?")
    Case 6 ; If it's a Yes
        ConsoleWrite("Yes" & @CRLF)
    Case Else
        ConsoleWrite("No" & @CRLF)
EndSwitch

Ask if anything is unclear.

M23

Thanks for the reply M23, I've taken out the optional parameters as you suggested and I actually managed to work out that (also as you said) I needed a result from the MsgBox and got it working with this:

$shutdown = MsgBox (4,"Shut Down?", "Do you want to shut down the machine after logging off of S/T?");Yes or No to shutting down the machine.

If $shutdown=6 Then ; If it's a Yes

I'm going to have a play with your code suggestions. Thanks for your help.

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  
Followers 0