VBScript Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.01

Quick Introduction of Visual Basic

Part:   1  2  

VB Script Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Data Types and Literals

Variables

Logic Operations

String Operations

Conditional Statements

Arrays

Loop Statements

Functions and Subroutines

Built-in Functions

Variable Inspection

... Table of Contents

(Continued from previous part...)

Now let's try to write our first VB script in a HTML document.

1. Open the Notepad to enter the following HTML document:

<html>
<body>
<script language="vbscript">
   document.write("Hello world! - VB Script")
</script>
</body>
</html>

2. Save the HTML document as hello_vb.html.

3. View the HTML document with IE. You should see the following message in the IE window:

Hello world! - VB Script

Congratulations. You have successfully written a VB script in a HTML document!

What happened here was:

  • We have added a "script" tag in our HTML document, hello_vb.html.
  • We included one VB statement inside the script tag.
  • That VB statement calls the "document.write" function, which is a function provided by IE to insert a text string into the HTML document.
  • We ran IE to view hello_vb.html and got exactly what we expected.

Using Visual Basic within Microsoft Access

Microsoft Access is a Microsoft application that can be used to store and manage data in database tables. Microsoft Access allows you to write add-on scripts in Visual Basic language.

If you have Microsoft Access installed on your system, you can follow the steps below to run a sample code in Visual Basic language in Microsoft Access.

1. Run Microsoft Access, and create a blank Access Database called vb_tutorial.mdb.

2. Click Insert > Module from the menu. The Microsoft Visual Basic window shows up.

3. Enter the following code into the empty code module:

Sub Main()
   MsgBox ("Hello world! - VB Access")
End Sub

4. Click File > Save from the menu. Enter "Hello" as the module name and save it.

5. Click Run > Run Sub/UserForm from the menu. The macro selection dialog box shows up.

6. Select "Main" macro, and click "Run". A dialog box shows up with the following message:

Hello world! - VB Access

Congratulations. You have successfully written a VB code module in Microsoft Access!

What happened here was:

  • We have added a VB code module called "Hello" to our Access database, vb_tutorial.mdb.
  • We have added a VB procedure called "Main" in the VB code module. Access calls this procedure as a macro.
  • The "Main" procedure calls the "MsgBox" function, which is a VB built-in function that displays Windows dialog box with the specified test message.
  • We ran the "Main" procedure and got exactly what we expected.

Conclusions

  • Visual Basic is programming language developed by Microsoft for Windows systems only.
  • Visual Basic can be used to write stand alone applications.
  • Visual Basic can be used to write add-on scripts.
  • Adding Visual Basic scripts in HTML documents is easy.
  • Adding Visual Basic code modules in Access databases is easy.

Part:   1  2  

Dr. Herong Yang, updated in 2006
VBScript Tutorials - Herong's Tutorial Notes - Quick Introduction of Visual Basic