Thursday, January 3, 2019


Data Types in vbscript

In vb script all variables are initialized with the data type called variant.
But we can have below sub-types in vb script.

In below table we have mentioned all sub data types in vb script. In next post we will see how to use these sub data types in vb script examples.


Subtype
Description
Empty
Variable is uninitialized. Value is 0 or ""
Null
Variable has Invalid data.
Boolean
True/False
Byte
Contains integer (0 to 255).
Integer
Contains integer (-32,768 to 32,767).
Currency
-922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long
Contains integer (-2,147,483,648 to 2,147,483,647).
Single
Contains a single-precision, floating-point number
Double
Contains a double-precision, floating-point number
Date (Time)
Contains a date
String
Contains a String
Object
Contains an object.
Error
Contains an error number.


Examples -

In below example we have a variable x and we have assigned a value 10 to x. In the next statement 
when we use typename method to check the data type of variable x then it will show it as a integer.

x = 10
MsgBox TypeName(x) 'prints integer
x = 11.1

MsgBox TypeName(x) 'prints double

If we store the value 11.1 in the same variable x, then it's data type will be shown as Double. So this is how data type of the variables keep changing in the VBScript. So VBScript language is called as loosely typed language. And the mechanism to determine the data type of variables at runtime is called as late binding.

Data Type Conversion
We can also convert the data type of the variable explicitly using various data type conversion functions.
For example - In below code we have a VBScript which will convert the decimal number into integer.
a = 11.3

Msgbox TypeName(a) 'prints double

a = cint(a)
Msgbox Typename(a) 'prints Integer

Other data type conversion functions are.
  1. cdbl - converts to double
  2. cstr - converts to string
  3. cbool - converts to boolean
  4. cbyte - converts to byte
  5. ccur - converts to currency
  6. cdate - converts to date
  7. clng - converts to long integer

Related Posts:

  • How to Restart a machine in vbscript? How to Restart a machine in vbscript? 'Warning - if you run this script, your computer will reboot/restart'Here you can specify name of computer you want to restart.....'. means local computerstrComputer = "."'create W… Read More
  • How to shutdown a computer in VBScript? How to shutdown a computer in VBScript? 'Warning - if you run this script, your computer will shut down'Here you can specify name of the computer you want to  shut-down.....'. means local computerstrComputer = ".… Read More
  • How to list all files in cookies in vbscript? How to list all files in cookies in vbscript? Cookie is a file stored by the web server on web client machine.If you want to find out the cookies in your machine you can use below program.Const COOKIES = &H21&S… Read More
  • Dynamic Arrays in VBScript example Dynamic Arrays in VBScript example In Vb script we can define the dynamic array in vb script as mentioned below.Size of dynamic array changes at run time. Example -Dim a () - declared dynamic array aTo use dynami… Read More
  • How to read the environment variables in your system in vbscript? How to read the environment variables in your system in vbscript? You can read the system variables using below program        'Create the WMI object strComputer = "." Set objWMIService = GetObject… Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

152,057

Blog Archive