iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

September 7, 2008
Web Design Clinic - Art meets Webdesign
About
 
September 6, 2008
Browser safe colors - do we care?
About
 
September 6, 2008
Get a Daily CSS Tip
About
 
September 5, 2008
It's safe to use Google Chrome now
About
 
September 5, 2008
Add a comment
.net
 
September 5, 2008
The Partial Function Application in JavaScript
WebReference.com
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /Visual Basic

VBScripts Tutorial I 

  Views:    20072
  Votes:    4
by Ahmad Permessur 12/12/03 Rating: 

Synopsis:

Welcome to a new series of tutorials on VBScripts. Throughout several lessons, I’ll teach you VBScripts. This isn't a hard thing to do, and it'll enhance your pages. In today’s lesson, I’ll focus a bit on the VBScript language itself, and on variables.
Pages: firstback1 2 forwardlast
The Article

Type of Variables

We all know that when we use variables within a program, we must define the type of variable; if the variable is used with integers, you declare the variable as an integer.  But defining each variable can result to problems in code and also create a complex structure that increases the overhead required for programs.

To avoid this, VBScript automatically allocates a variable type to any variable you define in your programs.  Variable types used by VBScript include: Boolean, Byte, Integer, Long, Single, Double, Date, String, Object, Error, Empty, and Null.

Generally, if you use whole numbers, such as 5 or 8, with a variable, VBScript creates the variable as an integer. Variables with values that use decimal points, such as 3.5 or 5.82, are usually assigned as double-precision floating-point values-Doubles. Variables entered with a mixture of alphabetical and numeric characters, such as H2O or 4-H, are created as Strings.

Because VBScript can automatically convert between some variable types, most variable conflicts are eliminated. However, if you try to add a String variable to a numeric variable type, you will get an error; so if a variable has alphanumeric characters, don't try to perform numeric calculations with it.

Note

Before performing calculations, you can make sure variables are numeric by using the IsNumeric function. This function returns a value of true if the variable is numeric and false if it isn't. This sample code checks for a numeric variable:

If IsNumeric(Value1) = True Then

    Value2 = Value1 + 5

These related functions check other variable types: IsDate, IsEmpty, IsNull, IsNumeric, and IsObject. 

Quick Recap

In today’s lesson, we learned a bit about the VBScript Language, its pros and cons too.  We’ve also learned how to insert our VBScripts within our HTML code by placing the VBScripts within the <SCRIPT LANGUAGE = “VBScript”> and </SCRIPTS> tags.  We followed the begin script tag with a begin comment tag, and precede the end script tag with an end comment tag to hide VBscripts to non-compatible browsers. 

I also taught you how to declare variables explicitly by using the Dim keyword followed by the variable name (e.g. Dim score) or implicitly by just assigning a value to a variable without first declaring it (e.g. score = 4).  And finally we discovered that we VBScript automatically allocate a variable type to any variable you define in our programs. 

Hope that this first tutorial on VBScripts has been helpful to you. Next time, we’ll learn on VBScripts’ arrays and on arithmetic and comparison operators. Your comments and questions are the most welcome.

Pages: firstback1 2 forwardlast

Similar/related articles:


 
  Sponsors