Numbers in VBScript
VBScript considers any unquoted, non-date value to be a number. Issuing the statement MyVariable = 5, for example, will assign the numeric value 5 to the variable MyVariable. The one catch in VBScript is that there are actually different types of numbers.
Any whole number-that is, a number with no decimal portion-is called an integer. The numbers 5, -6, 43,233, and -42 are all integers. VBScript integers can be anything from -32,768 to 32,767. VBScript also supports long integers, which are just big integers. They can be anything from -2,147,483,648 to 2,147,483,647. Numbers with a fractional value can be either singles or doubles. The only difference between them is in how large they can be. A single can be any numeric value from -3.4028235E+38 to -1.401298E-45, or from 3.4028235E+38 to 1.3401298E-45. In other words, a really big number. Sometimes, however, you may need an even larger number, which is where doubles come in. A double can be truly huge-as big as 1.79769313486231570E+308. I have no idea what you'd call a number like that other than humongous. VBScript also supports a currency number type. This has a maximum precision of four decimal places and has the added capability to properly recognize and format currencies based on the system's locale settings. That means you can properly display thousandths separators and decimal places according to the system configuration.
Now, as I mentioned in Chapter 5, you don't usually have to worry much about these different types of numbers, because VBScript does it for you. Variables in VBScript can hold any kind of data; if you try to put the number 64,555 into a variable, VBScript will just invisibly make the variable into a long integer. If you add .3 to it, VBScript will convert it into a single. The only time you'll need to worry about data types is if you want to perform some specialized function, like a currency operation, and then you'll need to explicitly convert the variable into the appropriate type-something I'll cover later in this chapter.
|