Skip to content

Instantly share code, notes, and snippets.

@simply-coded
Last active October 3, 2022 19:42
Show Gist options
  • Save simply-coded/4d80ce729c6cef8a860d466e8871323c to your computer and use it in GitHub Desktop.
Save simply-coded/4d80ce729c6cef8a860d466e8871323c to your computer and use it in GitHub Desktop.
Create multiple msgbox popups without waiting for a return value to continue.
Option Explicit
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim wsh : Set wsh = CreateObject("Wscript.Shell")
Dim args : Set args = WScript.Arguments
Dim this : this = WScript.ScriptFullName
Dim id, ans
'create message boxes
If args.count = 0 Then
'Message boxes that don't wait for a return to continue. Return values avaliable.
'Example: MsgStack "message", type, "title", numberID
MsgStack "First message box",vbYesNo+vbQuestion,"Title", 1
MsgStack "Second message box",vbInformation+vbOKCancel,"",2
MsgStack "Third message box",vbCritical,"Error",3
'return values for message boxes
ElseIf args.count = 2 Then
id = CInt(args(0))
ans = CInt(args(1))
'msgbox with id 1
If id = 1 Then
If ans = vbYes Then
MsgBox "you clicked [yes] on the first msgbox"
ElseIf ans = vbNo Then
MsgBox "you clicked [no] on the first msgbox"
End If
'msgbox with id 2
ElseIf id = 2 Then
If ans = vbOK Then
MsgBox "you clicked [ok] on the second msgbox"
ElseIf ans = vbCancel Then
MsgBox "you clicked [cancel] on the second msgbox"
End If
End If
'msgbox with id 3
'if statement here if you want a return
End If
'Function for no wait message boxes with return values.
Function MsgStack(message, options, title, id)
Dim temp
temp = fso.GetSpecialFolder(2) & "\" & Replace(fso.GetTempName, "tmp", "vbs")
With fso.CreateTextFile(temp)
.WriteLine "return = MsgBox(""" & message & """, " & options & ", """ & title &""")"
.WriteLine "CreateObject(""WScript.Shell"").Run """ & this & " "" & " & id & " & "" "" & return"
.WriteLine "CreateObject(""Scripting.FileSystemObject"").DeleteFile """ & temp & """, True"
.Close
End With
wsh.Run temp
End Function
Option Explicit
Dim wsh : Set wsh = CreateObject("Wscript.Shell")
'Message boxes that don't wait for a return to continue. No return values.
MsgBlank "message", "title"
MsgCritical "message", "title"
MsgInformation "message", "title"
MsgExclamation "message", "title"
'Functions for simple no wait message boxes without return values.
Function MsgBlank(m, t)
wsh.Run "mshta.exe vbscript:Execute(MsgBox("""&m&""",vbOkOnly,"""&t&""")(window.close))"
End Function
Function MsgCritical(m, t)
wsh.Run "mshta.exe vbscript:Execute(MsgBox("""&m&""",vbCritical,"""&t&""")(window.close))"
End Function
Function MsgInformation(m, t)
wsh.Run "mshta.exe vbscript:Execute(MsgBox("""&m&""",vbInformation,"""&t&""")(window.close))"
End Function
Function MsgExclamation(m, t)
wsh.Run "mshta.exe vbscript:Execute(MsgBox("""&m&""",vbExclamation,"""&t&""")(window.close))"
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment