VBScript is a weakly typed language; variables are all of type variant, though they usually have an implied subtype denoting the data they hold.
This means that your variable, no matter what you call it, can hold any value:
Dim foo
foo = "Hello, World!"
foo = 123.45
foo = #01-Jan-2016 01:00:00#
foo = True
Note that the above is perfectly valid code, though mixing your variables like this is amazingly poor practice.
The string subtype is always assigned by using speech marks " "
. Unlike JavaScript and other languages, the apostrophe does not provide the same functionality.
Numbers in VBScript can include any format of number, but do have a particular subtype based on their value and whether they contain a decimal point or not.
Dates use the # #
specifiers. Be aware that formats for a numeric date style (e.g. 01/01/2016) retains an American date format, so #05/06/2016#
is 6th May, not 5th June. This can be circumnavigated by using a #dd-mmm-yyyy#
format, as in the example above.
Boolean variables contain True
or False
values.
As explained earlier, arrays are dimensioned using a set of parentheses to define the number of elements and ranks (rows and columns), for instance:
Dim myArray(3, 4)
All elements in arrays are of type variant, allowing every single element to be of any subtype. This is very important when you need to perform tasks such as reading data from a record set or other object. In these cases, data can be directly assigned to a variable, for instance, when being returned from a record set...
Dim myData
....
myData = rsMyRecordset.GetRows()
....
Response.Write(myData(3,2))
One final type that requires some explanation is the Object
type. Objects are basically pointers to the memory location of the object itself. Object types must be Set
...
Dim myObj
Set myObj = Server.CreateObject("ADODB.ecordSet")