RSS Feed Link       View page in German   View page in Spanish   View page in French   View page in Italian   View page in Portuguese   View page in Japanese   View page in Korean   View page in Simplified Chinese   
Log On   Feedback   Search Site    
 
 
Home eZine Software Scripting Network Admin. SITE UPGRADE IN PROGRESS - CLICK HERE FOR INFO 
 
Reference Guide Table of Contents
Languages   UDF/UDC Libraries   Data Access   Visual Studio    

 

Select Area:

Information
ADSI
ASP
AutoIt
(D)HTML
KiXtart
MS-DOS / CMD
PowerShell
RunDLL32
ScriptIt
VBScript
WMI

 
   User Forum  | Links | Example Scripts
 

Math and Concatenation

Arithmetic

Arithmetic can be used against any numeric data type.  The following symbols are used:

! Name Description Example
+ Addition used to add numeric values together. dblResults = dblValueA + dblValueB
- Subtraction used to subtract numeric values together or negate a value. dblResults = dblValueA - dblValueB
/ Standard Division used to divide numeric values.  This style of division returns a floating-point number (fractional number) dblResults = dblValueA / dblValueB
\ Integer Division used to divide integer values. This style of division returns a whole number (integer).  No remainder dblResults = dblValueA \ dblValueB
MOD Modulo used to perform division on two numeric values and return only the remainder dblResults = dblValueA MOD dblValueB
* Multiplication used to multiply numeric values together. dblResults = dblValueA * dblValueB
^ Exponentiation Raises a number to the power of the exponent. dblResults = dblValueA ^ dblValueB

Concatenation

Concatenation is only used on string variables to combine them.  It does not perform any math.

! Name Description Example
& Standard used to concatenate string values together. strResults = strValueA & strValueB
+ Non-Standard used to concatenate string values together. strResults = strValueA + strValueB

Comparison

Comparison is used to compare the contents of two variables against each other.

! Name Description Example
> Greater Than Expression1 is greater than and not equal to Expression2 boolRetVal = objObject1 > objObject2
< Less Than Expression1 is less than and not equal to Expression2 boolRetVal = objObject1 < objObject2
<> or >< Not Equal Expression1 is not equal to Expression2 boolRetVal = objObject1 <> objObject2
>= or => Greater Than or Equal to Expression1 is is greater than or equal to Expression2 boolRetVal = objObject1 >= objObject2
<= or =< Less Than or Equal to Expression1 is less than or equal to Expression2 boolRetVal = objObject1 <= objObject2
= Equals Expression1 is equal to Expression2 boolRetVal = objObject1 = objObject2
IS Is Expression1 is  Expression2
This comparison operator is used only against object variables.  It can compare one object against another, or an object against a condition.
boolRetVal = objObject1 IS objObject2
boolRetVal = objObject1
IS Nothing

Logic

Logic operations are used to evaluate one or more expressions and return logical values.

AND - logical conjunction
As a comparison operator: Returns True only if Expression1 and Expression2 are true.
Comparison Examples: 
                    boolReturn = Expression1 AND Expression2
                    If y = 15 AND x < 23 Then

Expression1  Expression2  Result
True
True
False
False
True
False
True
False
True
False
False
False


As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Expression2 Bit  Result Bit
0
0
1
1
0
1
0
1
0
0
0
1

Essentially, the numeric values are evaluated at a binary level:
(147) 10010011
(58)  00111010
(18)  00010010


So, with this example, 147 AND 58 = 18
 

OR - logical disjunction
As a comparison operator: Returns True if Expression1 or Expression2 are true, and if Expression1 and Expression2 are true.
Comparison Examples: 
                    boolReturn = Expression1 OR Expression2
                    If y = 15 OR x < 23 Then

Expression1  Expression2  Result
True
True
False
False
True
False
True
False
True
True
True
False

As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Expression2 Bit  Result Bit
0
0
1
1
0
1
0
1
0
1
1
1

Essentially, the numeric values are evaluated at a binary level:
(147) 10010011
(58)  00111010
(187) 10111011


So, with this example, 147 OR 58 = 187
 

NOT - logical negation
As a comparison operator: Negates the Boolean value of Expression1
 

Expression1  Result
True
False
True
False

As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Result Bit
0
1
0
1

Essentially, the numeric values are evaluated at a binary level:
(58)  00111010
(197) 11000101


So, with this example, NOT 58 = 197
 

Eqv - logical equivalence
As a comparison operator: Returns True only if Expression1 equals Expression2
Comparison Examples: 
                    boolReturn = Expression1 Eqv Expression2
                    If y = 15 Eqv x < 23 Then

Expression1  Expression2  Result
True
True
False
False
True
False
True
False
True
False
False
True

As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Expression2 Bit  Result Bit
0
0
1
1
0
1
0
1
1
0
0
1

Essentially, the numeric values are evaluated at a binary level:
(147) 10010011
(58)  00111010
(86)  01010110


So, with this example, 147 Eqv 58 = 86
 

Imp - logical implication
As a comparison operator: Returns based on table below
Comparison Examples: 
                    boolReturn = Expression1 Imp Expression2
                    If y = 15 Imp x < 23 Then

Expression1  Expression2  Result
True
True
True
False
False
False
Null
Null
Null
True
False
Null
True
False
Null
True
False
Null
True
False
Null
True
True
True
True
Null
Null

As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Expression2 Bit  Result Bit
0
0
1
1
0
1
0
1
1
1
0
1

Essentially, the numeric values are evaluated at a binary level:
(147) 10010011
(58)  00111010
(126) 01111110


So, with this example, 147 Imp 58 = 126
 

Xor - logical exclusion
As a comparison operator: Returns based on table below
Comparison Examples: 
                    boolReturn = Expression1 Xor Expression2
                    If y = 15 Xor x < 23 Then

Expression1  Expression2  Result
True
True
True
False
False
False
Null
Null
Null
True
False
Null
True
False
Null
True
False
Null
False
True
Null
True
False
Null
Null
Null
Null

As a bitwise operator:  Compares the bits in both numeric expressions and returns a value based on the following:

Expression1 Bit  Expression2 Bit  Result Bit
0
0
1
1
0
1
0
1
0
1
1
0

Essentially, the numeric values are evaluated at a binary level:
(147) 10010011
(58)  00111010
(169) 10101001


So, with this example, 147 Xor 58 = 160

Operator Precedence

When evaluating a calculation line, the line is processed in the following operator order, and within each operator class, in the order listed.  When evaluating a line, multiple identical operators are processed from left to right.

Order Category Precedence
1 Arithmetic ^, (/ *), \, MOD, (+ -)
2 Concatenation (& +)
3 Comparison (No defined order, as listed from left to right)
4 Logical Not, And, Or, Xor, Eqv, Imp

If you need to override any given precedence, you place the single calculation element within parenthesis. 

As an example of how operator precedence works, copy/paste this code snippet into notepad, save it and run it to see how the totals differ:  Change the uncommented line to see the different calculations.

Dim dblRetVal

dblRetVal = 1 + 1 / 5
'dblRetVal = (1 + 1) / 5

WScript.Echo dblRetVal

Mathematical Related Functions

There are several functions you can use to assist with calculations:

Abs Abs(Number) Absolute Value
Atn Atn(Number) Inverse trigonometric function of Tan
Cos Cos(Number) Cosign
Hex Hex(Number) Converts a number into Hexadecimal
Log Log(Number) Logarithm
Oct Oct(Number) Converts a number into Octal
Sgn Sgn(Number) Sign
Sin Sin(Number) Sine
Tan Tan(Number) Tangent

 
Good Morning
8/20/2008 10:36:33 AM
Copyright © 1997 - 2008 Dx21, LLC. All rights reserved.
Dx21, LLC a Washington Limited Liability Company
  Privacy Policy | Terms of Use
   
Labelled with ICRA   Rated with SafeSurf