Introduction To Visual Basic
Introduction To Visual Basic
Figure 1.1
Your name and message will appear in the smaller box next to the
image, in the selected color and style.)
Chapter 1 P. 2
Note: the toolbox on your screen may not contain all the
icons shown on the text.
- toolbar (top) (Fig. 1.4)
Miscellaneous
- design time is the time spent writing the program
- run time is the time when the program runs
- break time is the time when the program stops because
- an error has occurred, or
- the user has suspended execution
Hello World
Push Me
Exit
Chapter 1 P. 9
When you click on “Push Me”, the “Hello World” appears.
Note: You must create this folder before you save your project.
(ii) Place the “Push Me” and “Exit” buttons on the form
(Fig. 1.13 - 1.16)
- from the toolbox select Command button
- draw a command button as you drew a label, or
double-click on the Command button
Chapter 1 P. 11
Note: double-clicking gives buttons of the same size.
(iii) Set the name and caption properties for the label
(Fig. 1.17 - 1.21)
- click once on the label
- click on the title bar of the Properties window
- scroll down to the Name property and type the
word lblMessage
This deletes the word “Label1” from the form. When the program
runs, the message “Hello World” will appear here.
(iv) Set the Name and Caption properties for the first
command button (Fig. 1.22)
- click on the Command1 button
- change the Name property to cmdPush
- change the Caption property to Push Me
(v) Set the Name and Caption properties for the second
Command button
- change the Name property to cmdExit
- change the Caption property to Exit
Chapter 1 P. 13
(vi) Set the Caption property for the form to the phrase
Hello World by your name (Fig. 1.23)
Assignment statements
- assignments place a value into a variable
- general form is object . property = value
-Example Book p. 20
- lblMessage.Caption = “Hello”
- lblTitle.FontSize = 12
You will see a new window with part of the code for the appropriate
procedure
Example If you run the program and get a message such as “Method
not available”, then this is a compile-time error.
Run-time errors
Definition If the program runs and then stops unexpectedly, then the
error which causes it to stop is called a run-time error.
Example At some point, you compute the value A/B, and you set B =
0.
Chapter 1 P. 22
Logic errors
Definition A logic error is an error which does not prevent the
program from running but which causes an incorrect value to be
returned.
NOTE: If you run a program and find no errors, then your test is
UNSUCCESSFUL!!!
Chapter 1 P. 23
Naming conventions
- names for controls
- Names for labels begin with lbl
- Names for command buttons begin with cmd
- Names for forms begin with frm
- names must not be Command1, Label1, etc.
- names must not be numbers