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

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

By Dan Mabbutt, About.com

1 of 10

How to use InputBox and MsgBox as the first examples of function statements

Simple MsgBox

Simple MsgBox

There are two main points to remember about the InputBox and MsgBox functions that are covered in the next few pages.

  • They're handy tools that we'll use a lot to learn about how VB.NET works. You'll find they're great debug your own programs. (I used the Debug.Write objects in my sample code in the previous lesson, but many programmers use these.)
  • They're also great examples of built in functions. You will learn how to code your own functions in Chapter 10 of the book.

One point that is mentioned in the book, but deserves a little more attention is the fact that a function must return a value. Both InputBox and MsgBox return values. InputBox is of little use unless the string that is returned is assigned to a variable (but it CAN be coded that way - try it if you doubt it), but the sample code in the book does not assign the returned value of MsgBox to a variable. Let's go beyond the book and see what can be returned by the MsgBox function and why.

Change the code to the example in the book to see what is returned:

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim MsgResult As MsgBoxResult
MsgResult = MsgBox(FullName, , "Input Results")
MsgBox(CStr(MsgResult), , "Returned From MsgBox")
~~~~~~~~~~~~~~~~~~~~~~~~~

In the next section of the book, we learn about fundamental data types and a little bit about data types in general. Later on, we learn more about object types. For now, it's enough to be aware that there are LOTSof types in VB.NET - not just strings and numbers.

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

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

All rights reserved.