3 Vba Fundamentals m3 Lang1 Slides
3 Vba Fundamentals m3 Lang1 Slides
Part 1
Terry Bradbury
[email protected]
Overview
Variant type
String type
Integer types
Boolean type
Floating-point types
Scaled types
Date type
Enumerations
Object types
User-Defined types
Variant Data Type
Byte (1 byte)
0 to 255
Integer (2 bytes)
-32,768 to 32,767
Long (4 bytes)
-2,147,483,648 to 2,147,483,647
LongLong (8 bytes – only on 64-bit systems)
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
LongPtr
Same as Long (Dword) on 32-bit systems
Same as LongLong (Qword) on 64-bit systems
The default value for all Integer types is 0
Boolean Data Type
Unsigned max value equals the sum of all the bit values
Signed max is half the sum of all bit values
Set MSB to indicate a negative value
Writing Binary
Binary Decimal
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2
0000 0011 = 3
Single
Negative values between -3.402823 x 1038 and -1.401298 x 10-45
Positive values between 1.401298 x 10-45 and 3.402823 x 1038
Double
Negative values between
-1.79769313486232 x 10308 and -4.94065645841247 x 10-324.
Positive values between
4.94065645841247 x 10-324 and 1.79769313486232 x 10308.
Will have rounded values for some expressions such as 1/3
Scaled Data Types
Currency (8 bytes)
15 digits to the left of the decimal, 4 to the right
In the range of -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Decimal (12 bytes)
Can have up to 28 decimal places
Is a subtype of variant
Use CDec to convert to decimal
Date Data Type
ErrObject (Err)
Collection
Global
ErrObject
Assignment ( = )
x = y + z
Set wks = ActiveSheet
Concatenation ( & )
FullName = FirstName & " " & LastName
TheAnswer = "Answer to the Ultimate Question of Life, " _
& "the Universe, and Everything is " & 42 & "."
Arithmetic Operators
Equality ( = )
Inequality ( <> )
Less than ( < )
Greater than ( > )
Less than or equal to ( <= )
Greater than or equal to ( >= )
Pattern matching ( Like )
Object reference comparison ( Is )
If (Obj1 Is Obj2) Then ' both reference same object
If (Obj1 Is Nothing) Then ' does not refer to any object
Bitwise Operators
And
Returns bits set in both values
Or
Returns bits set in either value
Xor (exclusive Or)
Returns bits that are different in both values
Not
Flips all the bits in a value
Logical Operators
And (Conjunction)
If ((2 + 2 = 4) And (4 + 4 = 8)) Then ' True
Or (Disjunction)
Xor (Exclusion)
Not (Negation)
Eqv (Equivalence)
Imp (Implication)
Essential Functions
Array
Conversion
DateTime
FileSystem
Information
Interaction
Math
String
Worksheet Functions (Excel only)
Array Functions
Array
Join
Split
LBound
UBound
Erase
Filter
Conversion Functions
CBool, CByte, CCur, CDate, CDbl, CSng, CInt, CLng, CLngLng, CLngPtr,
CStr, CVar
CDec
Can only be used with a variant
Hex, Hex$, Oct, Oct$
Int, Fix
Str, Str$
Val
DateTime Functions
Now
Date, Date$, Time, Time$
Year, Month, Weekday, Day, Hour, Minute, Second
Timer
DateAdd
DateDiff
DatePart
DateSerial, TimeSerial
DateValue, TimeValue
FileSystem Functions
ChDir Input
ChDrive Kill
CurDir, CurDir$ Loc
Dir Lock, Unlock
MkDir, RmDir Open, Close, Reset
Print
EOF, LOF Seek
FileAttr SetAttr
FileCopy
FileDateTime
FileLen
FreeFile
Financial Functions
DDB (double-declining balance)
FV (future value)
IPmt (interest payment)
IRR (internal rate of return)
MIRR (modified internal rate of return)
NPer (number of periods)
NPV (net present value)
Pmt (payment)
PPmt (principal payment)
PV (present value)
Rate (rate)
SLN (straight-line depreciation)
SYD (sum-of-years' digits depreciation)
Mathematic Functions
Abs (absolute)
Atn (arctangent)
Cos (cosine)
Exp (exponent)
Log (logarithm)
Randomize
Rnd (random)
Round (rounded)
Sgn (sign)
Sin (sine)
Sqr (square root)
Tan (tangent)
String Functions
IsArray
IsDate
IsEmpty
IsError
IsMissing
IsNull
IsNumeric
IsObject
QBColor
RGB
TypeName
VarType
Interaction Functions
AppActivate, Shell
Beep
CallByName
Choose, IIf, Switch
CreateObject, GetObject
DoEvents
Environ, Environ$
GetSetting, GetAllSettings, DeleteSetting, SaveSetting
InputBox
MsgBox
SendKeys
Worksheet Functions