spikyoneuk Posted July 31, 2009 Share Posted July 31, 2009 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 31, 2009 Moderators Share Posted July 31, 2009 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) EndSwitchAsk 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
spikyoneuk Posted July 31, 2009 Author Share Posted July 31, 2009 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. 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