locked
Pop up message vbscript RRS feed

  • Question

  • I have created a pop up message using msgbox "Text".

    does using this have    have either a line or car limit?

    I need to write more lines of text in the message But it does not show up.  Am I doing something wrong or is this a functiion of the msgbox?

    if it is can any one suggest a better way to do this pop up message?  it must also have an OK button at the end. 
    Thursday, January 8, 2009 8:44 PM

Answers

  • Hi Scott.

    The MsgBox Function can accept multiple line without limitations as far as i'm aware. You can easily add button controls to your Message boxes to prompt users...here is an example for you.

    Hope this helps

    Cheers

    Matt :)

    '----------------------------------------------------------------------------------------------------------------------------  
    'Script Name : MsgBoxExample.vbs  
    'Author      : Matthew Beattie  
    'Created     : 09/01/09  
    'Description : This script demonstrates how to use the MsgBox Function.  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Initialization  Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    Option Explicit  
    Dim objFSO, scriptBaseName  
    Set objFSO      = CreateObject("Scripting.FileSystemObject")  
    scriptBaseName  = objFSO.GetBaseName(Wscript.ScriptFullName)  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Main Processing Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    PromptScriptStart  
    PromptUser  
    PromptScriptEnd  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Functions Processing Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptScriptStart -> Prompt when script starts.  
    'Parameters : None              ->  
    'Return     : None              ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptScriptStart  
       MsgBox "Now processing the " & DQ(Wscript.ScriptName) & " script.", vbInformation, scriptBaseName  
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptScriptEnd -> Prompt when script has completed.  
    'Parameters : None            ->  
    'Return     : None            ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptScriptEnd  
       MsgBox "The " & DQ(Wscript.ScriptName) & " script has completed successfully.", vbInformation, scriptBaseName  
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptUser -> Prompts user to ensure they wish to execute the script.  
    'Parameters : None       ->  
    'Return     : None       ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptUser  
       Dim choice  
       choice = MsgBox("Now processing the " & DQ(Wscript.Scriptname) & " script." & vbCrLf & vbCrLf & _  
                      "Are you sure you wish to continue?", vbOKCancel + vbExclamation + vbDefaultButton2, scriptBaseName)  
       If choice = 2 Then 
          MsgBox "You have selected to cancel the " & DQ(Wscript.Scriptname) & " script. The script is now terminating.", _  
                  vbCritical, scriptBaseName  
          Wscript.Quit  
       End If 
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : DQ          -> Place double quotes around a string and replace double quotes  
    '           :             -> within the string with pairs of double quotes.  
    'Parameters : stringValue -> String value to be double quoted  
    'Return     : DQ          -> Double quoted string.  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function DQ (ByVal stringValue)  
       If stringValue <> "" Then 
          DQ = """" & Replace (stringValue, """", """""") & """"  
       Else 
          DQ = """""" 
       End If 
    End Function 
    '---------------------------------------------------------------------------------------------------------------------------- 
    • Proposed as answer by MatthewBeattie Thursday, January 8, 2009 10:00 PM
    • Marked as answer by IamMred Thursday, January 7, 2010 8:28 PM
    Thursday, January 8, 2009 9:59 PM
  • Hi Scott

    You might also find this helpful...

    http://msdn.microsoft.com/en-us/library/t1ft6yf3(VS.85).aspx

    If you only want an OK button just use the constant for "vbOKOnly"...for example

    choice = MsgBox("Now processing the " & DQ(Wscript.Scriptname) & " script." & vbCrLf & vbCrLf & _  
                    "Are you sure you wish to continue?", vbOKOnly + vbExclamation, scriptBaseName) 
    • Marked as answer by IamMred Thursday, January 7, 2010 8:28 PM
    Thursday, January 8, 2009 10:08 PM

All replies

  • Hi Scott.

    The MsgBox Function can accept multiple line without limitations as far as i'm aware. You can easily add button controls to your Message boxes to prompt users...here is an example for you.

    Hope this helps

    Cheers

    Matt :)

    '----------------------------------------------------------------------------------------------------------------------------  
    'Script Name : MsgBoxExample.vbs  
    'Author      : Matthew Beattie  
    'Created     : 09/01/09  
    'Description : This script demonstrates how to use the MsgBox Function.  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Initialization  Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    Option Explicit  
    Dim objFSO, scriptBaseName  
    Set objFSO      = CreateObject("Scripting.FileSystemObject")  
    scriptBaseName  = objFSO.GetBaseName(Wscript.ScriptFullName)  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Main Processing Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    PromptScriptStart  
    PromptUser  
    PromptScriptEnd  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Functions Processing Section  
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptScriptStart -> Prompt when script starts.  
    'Parameters : None              ->  
    'Return     : None              ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptScriptStart  
       MsgBox "Now processing the " & DQ(Wscript.ScriptName) & " script.", vbInformation, scriptBaseName  
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptScriptEnd -> Prompt when script has completed.  
    'Parameters : None            ->  
    'Return     : None            ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptScriptEnd  
       MsgBox "The " & DQ(Wscript.ScriptName) & " script has completed successfully.", vbInformation, scriptBaseName  
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : PromptUser -> Prompts user to ensure they wish to execute the script.  
    'Parameters : None       ->  
    'Return     : None       ->  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function PromptUser  
       Dim choice  
       choice = MsgBox("Now processing the " & DQ(Wscript.Scriptname) & " script." & vbCrLf & vbCrLf & _  
                      "Are you sure you wish to continue?", vbOKCancel + vbExclamation + vbDefaultButton2, scriptBaseName)  
       If choice = 2 Then 
          MsgBox "You have selected to cancel the " & DQ(Wscript.Scriptname) & " script. The script is now terminating.", _  
                  vbCritical, scriptBaseName  
          Wscript.Quit  
       End If 
    End Function 
    '----------------------------------------------------------------------------------------------------------------------------  
    'Name       : DQ          -> Place double quotes around a string and replace double quotes  
    '           :             -> within the string with pairs of double quotes.  
    'Parameters : stringValue -> String value to be double quoted  
    'Return     : DQ          -> Double quoted string.  
    '----------------------------------------------------------------------------------------------------------------------------  
    Function DQ (ByVal stringValue)  
       If stringValue <> "" Then 
          DQ = """" & Replace (stringValue, """", """""") & """"  
       Else 
          DQ = """""" 
       End If 
    End Function 
    '---------------------------------------------------------------------------------------------------------------------------- 
    • Proposed as answer by MatthewBeattie Thursday, January 8, 2009 10:00 PM
    • Marked as answer by IamMred Thursday, January 7, 2010 8:28 PM
    Thursday, January 8, 2009 9:59 PM
  • Hi Scott

    You might also find this helpful...

    http://msdn.microsoft.com/en-us/library/t1ft6yf3(VS.85).aspx

    If you only want an OK button just use the constant for "vbOKOnly"...for example

    choice = MsgBox("Now processing the " & DQ(Wscript.Scriptname) & " script." & vbCrLf & vbCrLf & _  
                    "Are you sure you wish to continue?", vbOKOnly + vbExclamation, scriptBaseName) 
    • Marked as answer by IamMred Thursday, January 7, 2010 8:28 PM
    Thursday, January 8, 2009 10:08 PM