Title: Distance Learning Center
1Distance Learning Center
- Lecture 3
- Introduction to Visual Basic
- Programming
- Melissa Lin, IT Consultant
- HenEm, Inc. Parkville, Missouri
- linm_at_ipfw.edu
- http//www.etcs.ipfw.edu/linm
2Lecture 3
- Modifying the example 1 from last class
- Finding and Fixing Errors Debugging
- Chapter 2 User Interface Design
- Using controls
- Setting Properties
- Objects
- Coding for the controls
- Summary
3Review Chapter 1
Help
Solution Explorer
Toolbox
frmHello Design
Properties
Click on Project1
On the Start page, click on the project1 from the
open an existing project, or Open it from the VB
File menu and choose Open
4Chapter 1 (continued)Solution Explorer
Properties Windows
code
Form
Scroll
5Modify Projects Add new controls
Label
Font
6Modify Projects Change Font
Size
Font Style
7Modify Projects (continue) Change Text Alignment
and Text
8Modify Projects (continue) Add a Spanish Button
9Modify Code - Spanish Button
Name Property spanishButton
Object Button
Text PropertySpanish
Hola Mundo is assigned to messageLabel.Text at
the current instance of a class.
Spanish
Private Sub spanishButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles spanishButton.Click ' Display the
Hello World message in Spanish.
messageLabel.Text "Hola Mundo" End Sub
10Modify Projects
11Explore the Editor Window
Class
Method
Class
12Modify the Project
- Understand the Program
- Plan and Design the GUI of Visual programming
- Named controls
- Define properties for each object
- Code procedures
- Write Remarks
- Option Strict On
- Save and compile
- Finding and Fixing Errors Debugging
- Implementation
The Form and all of the Controls on the form
are Objects.
Type this at the top of each code module.
13Modify Projects
14Save, Run, Close, Correct
- SAVE - Open the VB File menu and choose Save or
Save As to save the project - Run Build the project
- Debug Menu, Start
- Start (F5)
- Start Without Debugging (CTRL F5)
- Close - Open the VB File menu and choose Close or
Close it from the browser - Correct any Errors and Rerun
- Syntax errors (Compile errors)
- Run-Time Errors
- Logic errors
"Help is always available from the Help Menu or
by pressing F1."
15Finding and Fixing Errors
- Programming errors come in three varieties
Syntax Errors, Run-Time Errors, Logic Errors - Syntax Errors (Compile Errors)
- Statements that break VBs rules for punctuation,
format or spelling - Smart editor finds most syntax errors, compiler
finds the rest - Common sources of syntax errors are misspelling
an object name, property or method, keywords, or
using wrong punctuations
16Finding and Fixing Errors (continued)
- Syntax
- Error
- Error
- Message
17Finding and Fixing Errors (continued)
- Run-time Errors
- Statements or functions that fail to execute such
as impossible arithmetic operations, or
unexpected termination - Common source of these errors include division by
zero, attempting arithmetic operations on
non-numeric data, and taking the square root of a
negative number - Example Dim x As Double
- x Math.Sqr(-5)
18Finding and Fixing Errors (continued)
- Logic Errors
- Logic errors occur when the project runs but
produces incorrect results - Common sources of these errors include incorrect
calculations, display of the wrong information,
or incorrect formatting of output - These are generally the hardest errors to fix!
- They are errors made by the programmer or
designer - Well commented programs enable another programmer
to read the code and correct logic errors - Example area 2 pi r
19Finding and Fixing Errors (continued)
- VB Modes
- Design Time
- Run Time
- Break Time
- Option Explicit (in General code of each module)
- Comments
- Naming conventions (helloForm, messageLabel,
exitButton)
Debug Menu while running
Debug Menu before Starting
Stop Button
Break Button
Start Button
20Chapter 2More Controls - Toolbox
- More Controls
- types
- Text box
- Check box
- Radio button
- Group box
- Picture box
21Text Boxes
- TextBoxes
- Allows for user input
- Text Property
- What is displayed in text box
- What user entered in text box
- TextAlign Property
- Controls alignment of text in the text box
Select Alphabetical
22Group Boxes
- GroupBox
- Used as containers for other controls such as
radio buttons and check boxes - Improves readability of form
- Text Property
- What is displayed on the top edge of the group box
23Check Box
- CheckBox (can select more than one at a time)
- Allows the user to select or deselect one or more
items in any group - Checked Property
- Checked True
- Unchecked False
- CheckedChanged Event
- Text Property
- What is displayed next to the check box
24Radio Buttons
- RadioButtons (only one selection at a time)
- User may select only one in any group
- First create a group box and then create each
radio button inside the group box - Checked Property
- Checked True
- Unchecked False
- CheckedChanged Event
- Text Property
- What is displayed next to the radio button
25Picture Boxes
- Picture Box control
- Displays/contains an image
- Image Property
- Complete path and filename of graphic
- .bmp, .gif, .jpg, .jpeg, .png, .ico, .emf, .wmf
- SizeMode Property
- StretchImage causes picture to be resized to
match the size of the control - Visible Property
Image Properties button
26Picture Boxes (continue)
Properties button
Program Files -gt Microsoft Visual Studio .NET2003
-gt Common7 -gt Graphics -gt Icons -gt Flags
27Picture Boxes (continue)
- Images can be placed in a PictureBox
To place a size in the PictureBoxObject choose
from SizeMode Property
C\Program Files\Microsoft Visual Studio
.NET\Common7\Graphics\icons\Flags
28Borders and Styles
- BorderStyle Property
- None
- FixedSingle
- Fixed3D
29Drawing Lines
- Create a Label Object on a Form
- Clear the Text property
- Change the Backcolor to the desired color of the
line - Set the BorderStyle property to None
4 Lines
30Multiple Controls
- Select Multiple Controls
- Shift-Click or Ctrl-Click to select/deselect
multiple controls - Move, Align, Set common properties
- Select
- Hold left mouse button down to drag a selection
box around multiple controls OR hold control key
down while selecting OR hold shift key-down while
selecting - To move as a group just click on any one and drag
all - Common properties are shown in Properties window
- Format/Align/Size/Spacing allows various group
changes - Deselect
- Click elsewhere on form
31Multiple Controls (continue)- Group
- Point to one corner of a box surrounding the
controls, press the mouse button and drag to the
opposite corner - When lease the mouse button, each control has
selection handled - You can move, resize, and align them as a group
32Multiple Controls (continue)- Multiple Group
33Multiple Controls (continued)- Formatting
Multiple Controls
34What Can be Done with Multiple Selected Controls?
- Move them as a group
- Set their common properties
- Use Format Menu or Layout Toolbar to
- Align them to each other
- Make same size
- Modify the spacing between them
35Summary
- Modify the example from last class
- Finding and Fixing Errors
- Syntax Error, Run-time Errors, Logic Errors
- Chapter 2 User Interface Design
- Use more controls
- Set Properties
- Next
- Design for User Convenience
36Question?
- Answers
- linm_at_ipfw.edu
- lin_at_ipfw.edu
- BnBartholme_at_hotmail.com