Visual Basic.NET
  Home arrow Visual Basic.NET arrow Mastering the Message Box
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Mastering the Message Box
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2009-07-20

    Table of Contents:
  • Mastering the Message Box
  • Controlling the appearance
  • Understanding Bitwise Flags
  • Controlling other options
  • Putting it all together
  • Catching bugs

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Mastering the Message Box


    (Page 1 of 6 )

    It’s not uncommon for programmers to build scripts that communicate with the end user. Whether the script is delivering a notification or asking the user to make a choice, most programmers will turn to the simple message box. But there’s more to the message box than meets the eye! From controlling the title bar text and icon to its appearance and behavior, the message box provides many different customizable options. Today we’re going to explore all of those options—even the ones you won’t find in the MSDN documentation!

    Message boxes are displayed by using the MessageBox function of the Win32 API.  Both VBScript and Visual Basic for Applications provide a MsgBox function that allows limited use of the API MessageBox function.

    The WshShell object’s Popup method, on the other hand, provides more thorough access to the MessageBox function.  The MSDN documentation for the Popup method and the MessageBox function are incomplete at best, so learning to use them takes a little trial and error.  Luckily, I’ve already done that for you.  Let’s take a look at the syntax for the Popup method.

    intButton = object.Popup(strText,[nSecondsToWait],[strTitle],[nType])

    The Popup method has one required parameter, which is a string value containing the prompt to be displayed in the message box.  According to the documentation, it returns an integer value that indicates the button that the user pressed.  This is incorrect. It actually returns a Variant value that can be interpreted as a Long type integer, as I’ll explain later.

    The Popup method also accepts three additional optional parameters.

    nSecondsToWait is an integer value indicating the number in seconds the message box should display before timing out.  Omitting this value or specifying 0 will cause the message box to remain on the user’s screen until they press a button.

    strTitle accepts a string value that will be displayed in the title bar of the message box.  If this value is Null (or omitted) the title will default to “Windows Script Host” in WSH or the API’s default “Error” in VBA.

    nType accepts an integer value that represents a combination of bit flags specifying the various options for the message box.  This is the most complicated part of the process, and we’ll talk about this in detail later in this article.

    You can display a simple message box using the following code for WSH or VBA.

    ' WSH

    Set WshShell = CreateObject("WScript.Shell")

    intReturn = WshShell.Popup("Hello, world!")

     

    ' VBA

    ' Add a Reference to Windows Script Host Object Model

    Dim WshShell As IWshRuntimeLibrary.WshShell

    Set WshShell = New IWshRuntimeLibrary.WshShell

     

    Dim lngResult As Long

    lngResult = WshShell.Popup("Hello, world!")

    More Visual Basic.NET Articles
    More By Nilpo


     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek