Monday, November 3, 2014

VBScript Operators

Operator which perform operations on operands. Where operands can be variable,string or some other object.

'VBScript language supports following types of operators:
'1. Arithmetic Operators
'2. Comparison Operators
'3. Logical (or Relational) Operators
'4. Concatenation Operators


Dim a 'Declaration

a=20 'Initialisation
b=3 'Declaration and Initialisation

MsgBox "A  = "& a & " B =" & b

MsgBox "A + B = "& a+b

MsgBox "A - B = "& a-b

MsgBox "A * B = "& a*b

MsgBox "A / B = "& a/b

MsgBox "A MOD B = "& a MOD b

MsgBox "A ^ B = "& a^b

---------------------------------------------------------------------------------





Dim a 'Declaration

a=10 'Initialisation
b=20 'Declaration and Initialisation

MsgBox "A  = "& a & " B =" & b

MsgBox "A == B = "& a = b

MsgBox "A <> B = "& a <> b

MsgBox "A > B = "& a > b

MsgBox "A < B = "& a < b

MsgBox "A >= B = "& a >= b

MsgBox "A <= B = "& a <= b


----------------------------------------------------------------------




Dim a 'Declaration 

a=10 'Initialisation
b=0 'Declaration and Initialisation

Result = ""

If a<>0 AND b<>0 Then                    
     Result = Result &"AND Operator Result is : True"
     Result = Result & vblf 'Inserting a Line Break for readability
  Else
     Result = Result &"AND Operator Result is : False"
     Result = Result & vblf 'Inserting a Line Break for readability
  End If

  If a<>0 OR b<>0 Then
     Result = Result &"OR Operator Result is : True"
     Result = Result & vblf
  Else
     Result = Result &"OR Operator Result is : False"
     Result = Result & vblf
  End If

  If NOT(a<>0 OR b<>0) Then
     Result = Result &"NOT Operator Result is : True"
     Result = Result & vblf
  Else
     Result = Result &"NOT Operator Result is : False"
     Result = Result & vblf
  End If

  If (a<>0 XOR b<>0) Then
     Result = Result &"XOR Operator Result is : True"
     Result = Result & vblf
  Else
     Result = Result &"XOR Operator Result is : False"
     Result = Result & vblf
  End If

MsgBox Result


------------------------------------------------------------------------




Dim a : a = 5
Dim b : b = 10
Dim c
Dim Result : Result = ""

  c=a+b
  Result = Result & "Concatenated value:1 is " &c 'Numeric addition
  Result = Result & vblf 'Inserting a Line Break for readability
  c=a&b
  Result = Result &"Concatenated value:2 is " &c  'Concatenate two numbers
  Result = Result & vblf 'Inserting a Line Break for readability

MsgBox Result