Current time: 02-05-2012, 03:53 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Message Box
09-12-2009, 11:54 PM
Post: #1
Message Box
If i create a message box, how do I get the script to run a different line when the user clicks ok?

undefined
Find all posts by this user
Quote this message in a reply
09-13-2009, 10:08 AM
Post: #2
RE: Message Box
You need to capture the return value from the message box. Remember that although MsgBox() is often used like a subroutine, it's actually a function that returns an integer value. There are several possible return values depending on the buttons you display, but it's much easier to remember VBScript's constants instead. Try something like this:
    VBS Programming
  1. intReturn = MsgBox("Press a button", vbOK & vbCancel)
  2. Select Case intReturn
  3. Case vbOK
  4. ' Do something here
  5. Case vbCancel
  6. ' Do something else here
  7. Case Default
  8. ' Something went very wrong.
  9. End Select


Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!
[Image: tsig.php]
Help us help you! Post your exact error message with these easy tips!
Visit this user's website Find all posts by this user
Quote this message in a reply
09-13-2009, 11:59 AM
Post: #3
RE: Message Box
(09-13-2009 10:08 AM)Nilpo Wrote:  You need to capture the return value from the message box. Remember that although MsgBox() is often used like a subroutine, it's actually a function that returns an integer value. There are several possible return values depending on the buttons you display, but it's much easier to remember VBScript's constants instead. Try something like this:
    VBS Programming
  1. intReturn = MsgBox("Press a button", vbOK & vbCancel)
  2. Select Case intReturn
  3. Case vbOK
  4. ' Do something here
  5. Case vbCancel
  6. ' Do something else here
  7. Case Default
  8. ' Something went very wrong.
  9. End Select


Something like this...

    VBS Programming
  1. Dim strPassword
  2. strPassword = LCase (InputBox ("Guess the Secret Word!"))
  3. If strPassword = "scripting" Then
  4. intCorrectResult = MsgBox ("Correct", vbOK & vbCancel)
  5. ElseIf strPassword = "" Then
  6. intTryResult = MsgBox ("You have to try, silly.", vbOK)
  7. Else
  8. intNopeResult = MsgBox ("NOPE!", vbOK)
  9. End If
  10.  
  11. Select Case intCorrectResult
  12. Case vbOK
  13. WScript.quit
  14. Case Else
  15. WScript.quit
  16. 'Case vbCancel
  17. 'WScript.quit
  18. End Select
  19. Select Case intTryResult
  20. Case vbOK
  21. 'goto dim strPassword
  22. strPassword
  23. 'WScript.strPassword
  24. Case Else
  25. WScript.quit
  26. End Select
  27. Select Case intNopeResult
  28. Case vbOK
  29. strPassword
  30. Case Else
  31. WScript.quit
  32. End Select


undefined
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


Forum Permissions
You cannot post new threads.
You cannot post replies.
You cannot post attachments.
HTML is turned off.
MyCode is turned on.
Smilies are turned on.
[img] is turned on.