Visual Basic Commands


Here are the VB operators used to perform mathematical operations on one or more variables. Aside from the normal multiply/add/substract and divide, you will find the AND, OR, Not Equal, MOD and Integer Division operators very useful.


PART1 :


/ - Normal division
\ - Integer division (truncates the answer)
^ - Exponentiation operator
* - Multiply
+ - Plus
- - Minus
= - Equal
> - Greater Than
< - Less Than
<> - Not Equal
>= - Greater than or equal
<= - Less than or equal
AND - Defines a boolean value that is the AND of two values result = expression1 AND expression2
OR - Defines a boolean value that is the OR of two values result = expression1 OR expression2
XOR - Defines a boolean value that is the exclusive OR of two values result = expression1 XOR expression2
NOT - Defines an opposite boolean value A = NOT B
EQV - Performs a logical equivalence on two expressions (result is true if both expressions are true) result = expression1 EQV expression2
IMP - Performs a logical implication on two expressions result = expression1 IMP expression2
IS - Determines if 2 variables reference the same object result = object1 IS object2
LIKE - Determines if one string matches a pattern result = string LIKE pattern
MOD - Returns the integer remainder of a division i = 27 MOD 5
Math
VB also provides built-in functions which can act on variables. Most are self-explanatory. In my experience, the VAL, RND, and ROUND functions are among the most valuable, so be sure to pay close attention to them!
Round - Rounds a number to a selectable number of decimal places result = round ( tempvariable,2 )
Val - Returns the numerical content of a string result = Val ("123.4")
Int - Returns an integer by truncating (different than Fix) i = int ( tempvariable )
Fix - Returns an integer by truncating (different than Int) i = fix ( tempvariable )
Hex - Returns the hexadecimal value of any number temp$ = hex ( tempvariable )
Oct - Returns the octal value of any number temp$ = oct ( tempvariable )
Tan - Returns the tangent of an angle tempvariable1 = tan ( tempvariable2 )
Rnd - Returns a random number between 0 and 1 tempvariable1 = rnd
Randomize - Initializes the Rnd function so it gives different answers each time randomize
Sgn - Returns the sign of a number i = sgn ( tempvariable )
Sin - Returns the sine of an angle tempvariable1 = sin ( tempvariable2 )
Cos - Returns the cosine of an angle tempvariable2 = cos ( tempvariable )
Abs - Converts a number to a positive value i = abs ( tempvariable )
Sqr - Returns the square root of a number tempvariable1 = sqr ( tempvariable2 )
Log - Returns the base 10 logarithm of a number tempvariable1 = log ( tempvariable2 )
Atn - Returns the arctangent of an angle tempvariable1 = atn ( tempvariable )
Partition - Sort of an oddball function but segregates values according to ranges
Type Conversions - A variety of conversion functions
CBool, CByte, CCur, CDate, CDbl, CDec, CInt, CLng, CSng, CStr, CVar
Strings
In my experience these functions are used more than just about any of the other VB built-in functions. The FORMAT, MID, and INSTR functions are incredibly powerful and I use them extensively. If you don't understand what they are, they are worth the time to figure out! The LEN and CHR functions are also valuable as are the variations on the trim and case functions.
Left - Returns the left n characters of a string temp$ = left$ ( teststring$, 4 )
Right - Returns the right n characters of a string temp$ = right$ ( teststring$, 4 )
Trim - Removes leading and trailing spaces of a string temp$ = trim$ ( teststring$ )
LTrim - Removes only the leading spaces of a string temp$ = ltrim$ ( teststring$ )
RTrim - Removes only the trailing spaces of a string temp$ = rtrim$ ( teststring$ )
UCase - Makes all characters upper case temp$ = ucase$ ( teststring$ )
LCase - Makes all characters lower case temp$ = lcase$ ( teststring$ )
Mid - Returns n characters from a string, starting a any position temp$ = mid$ ( teststring$, 1, 4 )
Len - Returns the length of a string (how many characters it has) temp$ = len ( teststring$ )
LSet - Positions a string inside another, flush to the left temp$ = lrset ( teststring$ )
RSet - Positions a string inside another, flush to the right temp$ = rset$ ( teststring$ )
Format - Returns a string formatted according to a user-defined format temp$ = format$ ( teststring$, "####.0" )
String - temp$ = left$ ( teststring$, 4 )
Chr - Returns the string representation of a number temp$ = str$ ( 32 )
Asc - Returns the ASCII code of a single character temp$ = asc ( "A" )
Space - Returns n spaces temp$ = space$ ( 15 )
Instr - Determines if one string is found within a second string i = Instr (starthere, string1, string2)
InStrRev - Determine if one string is found in a second, starting at the end i = InStrRev (string1, string2, start)
StrComp - Compares two strings result = StrComp (string1, string2)
StrConv - Converts the case of a string's characters StrConv (string, vbuppercase)
StrReverse - Reverses character order in a string StrReverse (string1)
Replace - Replaces each occurrence of a string Replace (bigstring, searchstring, replacementstring)
FormatCurrency - Returns a string using a currency format FormatCurrency(var1, 2)
FormatDateTime - Returns a date or time expression FormatDateTime("3/2/99",vbShortTime)
FormatNumber - Returns a number formatted according to a variety of options FormatNumber(var1, 2)
FormatPerCent - Returns a number formated as a percent FormatPerCent(var1, 2)
Arrays