Vbscript-the Easy Stuff-page 2

Source: Internet
Author: User
Tags alphabetic character integer variables range
VBScript

Vbscript-the Easy Stuff-page 2

Chris Assenza

February 5, 2001


Variables
I am The Everyone knows what a variable is, but to being safe, a variable is a little chunk the memory in which a value of vary The ing type (like characters and numbers) can is stored and manipulated. The is isn't the most precise or technical definition that could being used, but I suspect everyone gets the picture. Variables are what the different values floating around in your. As I hinted at the rather blatantly above, variables can take on many different forms. They can be strings (a string are one or more characters-like a sentence to example), integer, floating point number, a Date, and all sorts of the other useful things.

One advantage to a scripting language are that it's not strongly typed. Or, in the other words, to use a variable it does not need to is declared with a type defined. Whereas in a strongly-typed language like C + +, you are need to declare not only the variable but type of what it is.

In VBScript there are really only one type, Variant. Therefore, all VBScript variables are of type Variant (which means they can basically is anything) and May is any of the F Ollowing sub-types:

Subtype DESCRIPTION
Empty Variant is uninitialized. The Value is 0 for numeric variables or a zero-length string ("") for string variables.
Null Variant intentionally contains no valid data.
Boolean Contains either True or False.
The Byte Contains integer in the range 0 to 255.
Integer Contains integer in the range-32,768 to 32,767.
currency-922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long Contains Integer in the range-2,147,483,648 to 2,147,483,647.
Single Contains A single-precision, floating-point number in the Range-3.402823e38 to-1.401298e-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
Double Contains A double-precision, floating-point number in the range-1.79769313486232e308 to-4.94065645841247e-324 fo R negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
Date Contains A number that is represents a date between January 1 to December 31, 9999.
String Contains A variable-length string that can is up to approximately 2 billion characters in length.
Object Contains an object.
Error Contains an error number.
Source:microsoft Scripting Technologies

The neat thing about the Variant thing is ' that ' you don't really need to worry about. It'll figure out what sub-type the variable are, based on how to use it. What is important to recognize are that if your utilize a variable as one sub-type (say as an integer) and then try to store A string in the it later, that would return an error because of a mismatch.

To use a variable in code, it the has to be declared-or memory spaces has to is set aside for it. VBScript uses the "DIM" statement to declare variables (there are others but we don't need to worry about those right now ). This is the example of using the Dim statement.


<%
' This little single apostrophe is a comment,
' It allows ' to put explanation in your
' Code and not have the interpreter run it!

' Use this as notes to yourself for what code
' Does or notes for future developers working
' On your page!

' Using the Dim Statement

Dim myvariable
Dim anothervariable, X, Y, Count
%>

The above code is very simplistic. The statement sets up a variable called myvariable. The second line declares Anothervariable, X and Y all in basically the same time. It is there to simply demonstrate this can declare more then one variable/line, as long as you separate each varia ble with a comma.

Now before ' all excited and start declaring variables until your heart are content, you should know that there are a Few restrictions for naming variables. They must begin with a alphabetic character (i.e. They cannot start with a number), They cannot-contain an embedded Perio D (ie. no my. Variable type naming is acceptable), they cannot exceed 255 characters, and they must be uniquely named (i.e. cannot have Two different variables named Jim in the same function or sub).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.