Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 5 - VB.NET Language and Syntax - Part 2

By Dan Mabbutt, About.com

2 of 10

"Magic" Numbers in the Code

Complex MsgBox

Complex MsgBox

Dan Mabbutt

MsgBoxResult and MsgBoxStyle are just two more types available to you which help you be more precise in your code.

This gives you a final MsgBox like the one shown on the previous page. But what does that mean? You probably noticed the Intellisense messages that actually tell you when you coded the example.

"Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality of the message box. If you omit Buttons, the default value is zero."

This means that you can make a message box display the cool little symbols and buttons like Yes, No, and Cancel automatically by just using the right value when the MsgBox function is called. In other words, changing the statement to:

~~~~~~~~~~~~~~~~~~~~~~~~~
MsgResult = MsgBox(FullName, 67, "Input Results")
~~~~~~~~~~~~~~~~~~~~~~~~~

... will give you a message box like the one shown at the top of this page. But where did that "magic number" 67 come from? One answer is that it's just part of how MsgBox works. But VB.NET gives you a real boost in figuring out what these numbers are. They are part of what are called enumeration values and they're described in the VB.NET help system and in MSDN online as well as in the Intellisense popups in Visual Studio .NET. The value I used, 67, is obtained by adding the value of vbYesNoCancel which is 3 to the value of Information which is 64 to get 67.

Explore Visual Basic

By Category

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.