Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 7 Using Loops and Timers 205



  1. Scroll down in the list box, and then double-click the Windows System - Logging,
    Processes, Registry, Services folder.
    In this folder, you’ll find snippets related to querying and setting operating system
    settings.


Tip If you are using Visual Basic 2010 Express, you might not see the Windows System -
Logging, Processes, Registry, Services folder. If you do not see this folder, you can just type
the code listed in Step 7.


  1. Double-click the Windows - System Information folder.


A list of system information snippets appears. Now you’ll select the snippet that returns
information about the current version of Windows.


  1. Double-click the snippet entitled “Determine the Current Windows Version .”


Visual Studio inserts the following line of code into the Button1_Click event procedure
at the insertion point:

Dim osVersion = My.Computer.Info.OSVersion
These statements declare the string variable osVersion to hold version information about
the operating system, and then use the Computer.Info object to fill the variable with current
information. The snippet also uses the My namespace to gather information about your
computer. The My namespace is a “speed-dial” feature of Visual Basic designed to reduce the
time it takes to code common tasks, and I will introduce it more fully in Chapter 13.
This code snippet is called a template because it supplies the majority of the code
that you need to insert for a particular task, but the code is not fully integrated into
your project yet. In this case, we should add a second variable to hold the name of
the operating system (because there are different Windows versions), and we’ll add
a MsgBox function to display the results for the user. (In other cases, you might need to
add controls to your form, create new variables or data structures, or write additional
program statements that use the snippet .)


  1. Press the ENTER key twice to add a blank line below the snippet.

  2. Type the following program statements:


Dim osName = My.Computer.Info.OSFullName
MsgBox(osName & vbCr & osVersion)
These statements declare a second string variable named osName that will hold the
Windows version retrieved by the OSFullName property of the Computer.Info object. There
is also a MsgBox function that displays the two returned values: the operating system name
(osName) and the operating system version number (osVersion). As you probably know,
the operating system version number has now become quite detailed in Windows because
Free download pdf