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:

  • What are different conditional statements in vbscript? What are different conditional statements in vbscript? In Vbscript there are 2 types of conditional statements. if ...else Select Case Example of if else -  a = 10 If a > 10 Then Msgbox "a is greater t… Read More
  • Difference between procedures and functions in vb script Difference between procedures and functions in vb script Major difference between procedures and functions in vb script is that procedures can not return the value but functions can return the value.Procedure Example… Read More
  • Loops in Vbscript Loops in Vbscript Here is the list of different looping statements in vbscript. For ....Next For Each ...Next Do While...Loop Do Until....Loop While...Wend 'You can exit from For Loop with Exit For statement'For Loo… Read More
  • String functions in vbscript String functions in vbscript Below is the list of string functions in vb script lcase ucase len left right mid ltrim rtrim trim replace strreverse string Instr Instrrev strcomp We are going to have a look at each St… Read More
  • Sub Procedures in VBScript Sub Procedures in VBScript Sub procedures are used to perform the specific task. Sub procedures are used to increase the reusability of the code. Simple example of the procedure Suppose you want to find the sum of … Read More

0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

151,638

Blog Archive