Tutorial 3
Variables
Types
Byte - 0
to 255 (byt)
Boolean - TRUE or FALSE (b)
Currency
- Number up tp 15 digits to left of decimal and 4 digits to right (cur)
Date -
1/1/100 - 12/31/9999 (dtm)
Double -
+-5E-324 to 1.8E308 (dbl)
Integer
- 32768 to 32767 (int)
Long -
+- 2 billion (lng)
Single -
+- 1E-45 to 3E38 (sng)
String -
text 1 to 65,400 characters (str)
Variant
- any other type (var)
Naming
begin
with letter
letters,
digits, underscore
not more
than 255 characters
cannot
be a reserved word
Declaring
Dim Dim {variable name} as {datatype}
Public Public {variable name} as {datatype}
- Global Variables
Constants
Literal
Constant - an item of data whose value does not change ex. 500
Symbolic
Constant - memory location whose contents do not change
while program is running
Const {constant name} as {datatype}
Const
strPath = "C:\temp"
Const
pi as double = 3.14
Public Const {constant name} as
{datatype}
Scope
objects
event procedure
form
code
module declaration seciton - global variables
Option Explicit
requires
declaration of all variables, without it any variable that is not declared witn
DIM
or Public is type integer
Code Module
separate file that contains code
Choose
Project on menu bar, Add Module(bas extension)
Concatenating Strings
strTemp = "Help" & " " &
"me"
strTemp2 = strTemp & " the end."
InputBox Function
InputBox(prompt,title)
strName = InputBox("Name","Enter Name
Dialog")
vbNewLine character
symbolic constant
chr(13) & char(10)
Default Button
Button chosen whenver {enter} is presses
set default property of button
Adding a form
Existing form
choose
project menu, Add Form
Specifying Startup form
Project properties
Form Statements
Load - brings form into memory - Load {formname}
Unload - removes form from memory - UnLoad {formname}
Form Methods
{form}.Hide - Hides the form
{form}.Show - Display form
Types of forms
modeless - can take action on other forms in applications
modal - no action can be taken on another form in application until form is unloaded or hidden
Center form on scree
{formname}.Top =(screen.Height - {formname}.Height/2
{formname}.Left =(screen.Left - {formname}.Left/2
Timer Control
to perform some action at specified time intervals
Interval Property - set im millisecomds
Place code in Timer event