Beginning Visual Basic

advertisement
Instructor’s Notes
Beginning Visual Basic
Designing Applications
Beginning Visual Basic
(107-172)
Designing Applications
Notes
Activity
TOE Chart
 Task – Object – Event
 In task column, list tasks program must do
(inputs, calculations, outputs)
 In object column, list object across from task that will be
used to meet the task requirement
- Text, option, list, combo, check for input
- Labels for output
- Command buttons for calculations
 In event column list the event that triggers the calculation
(or output)
 Authors suggest sort by object once ICO complete. Good
idea. Suggests using a spreadsheet to create TOE chart
(nice columns and rows; easy to resort)
Screen Layout
 Rough sketch OK but ease of use of VB interface (drag
and drop objects) makes it just as easy to prototype using
VB.
 Pick one layout style: vertical or horizontal (page 102).
Mix usually doesn’t work too well
 Vertical layout
 Field labels to left, labels left aligned
 Command buttons on button of screen
 Horizontal layout
 Field labels on top of fields, left aligned
 Command buttons on right side of screen
 Windows standards
 6 or fewer command buttons
 Labels end with a colon (:)
 Labels use sentence capitalization
 Command buttons use title capitalization
 Size items consistently
 Keep 2-dot margin on all sides
 Keep command buttons close to each other
 See font tips page 112 (not too critical in this class)
Review guidelines page
104 & 107
Layout Bowling Program
Format a textbox and copy
Format a label and copy
1
Instructor’s Notes
Beginning Visual Basic
Designing Applications
Notes
Screen Layout (con’t)
 See color tips on page 113 (not too critical as long as not
annoying mix)
 Set BackStyle of labels to transparent. Looks good and
allows changing form’s BackColor without having to
modify labels.
 Labels with borders shouldn’t be 3-D (Windows
standard) (negotiable)
Activity
Tab Index
 Controls the order objects are visited when user presses
Tab key
 Start at 0
 When reset a tab index, all objects with a higher (or
equal) number tab index will automatically renumber
 Can remove an object from the tab order by setting its
TabStop property to false.
Add a new field to the form
(date).
Locking Objects
 Keeps you from accidentally moving an object on a form
once you’ve placed it appropriately.
 Right-click in open area in form and choose Lock
Controls
Lock then unlock controls
Access (Shortcut) Keys
 You can assign shortcut keys to any input object or
command button.
 Add “&” before the appropriate letter in the object’s
caption property (usually first letter, but may have to
handle duplicates).
 Alt-key provides keyboard shortcut to the object
 Since text boxes don’t usually have text to apply an & to,
place & in the text box’s label.
 Make sure the text box’s label tab index is one less
than the text box tab index.
 Since a label can not be tabbed to (is not an input
stop), when you press the shortcut key, focus is
automatically transferred to the next object (the text
box)
Assign shortcut keys to
command buttons first,
then any appropriate
objects
Reset tab order
appropriately.
Note how Access has
improved this significantly.
Note: images, labels etc. all
locked.
Assign shortcut keys to
command buttons
2
Instructor’s Notes
Beginning Visual Basic
Notes
Visual Basic Equations
 Review operators on page 138
 To use values in a text box in an equation (mathematical)
you have to convert to a value first
 Val(object.txt)
Formatting Results
 Results appear in a general format similar to Excel’s
general format
 To instruct VB to format your output differently, use the
format function
 label.Caption = Format(object, “format”)
 Formats (for “format”):
 Currency ($1,000.00)
 Fixed (1000.00)
 Standard (1,000.00)
 Percent (x100 25.00%)
 Month m mm mmm mmmm
 Day d dd ddd dddd
 Year yy yyyy
 Hours h hh
 Minutes n nn (m used for month)
 Seconds s ss
 $#,##0.00
Designing Applications
Activity
Try c = a + b without Val
function first: concatenates.
Add Val function to all text
fields
Calc Series and Average
Create buttons to format a
value in different ways
Create a button to reformat
a date. Experiment with
different date formats.
Just like Access.
Format Average Fixed
Format Date (in
cmdClear_Click and
LostFocus)
Printing a Form
 Don’t usually want command buttons displayed so shrink
the height of the form (hides buttons)
 PrintForm method
 Set form height back to original size
Won’t be using this much
in class, but here’s how.
SetFocus Method
 Allows moving focus (object currently in use) during run
time.
 Often applied after a command button to place focus on
the appropriate object (after printing or clearing form or
calculating values for instance)
 Objectname.SetFocus
After printing SetFocus
appropriately (Clear)
Create Print button but
comment out the
‘PrintForm command
3
Instructor’s Notes
Beginning Visual Basic
Designing Applications
Notes
Clearing Text boxes or Labels at Runtime
 Set Text or Caption property to “” (empty string; no
spaces in between)
 TxtName.Text = “” lblTotal.Caption = “”
Activity
Code a clear button
Set Date to Now
SetFocus after clearing
(Game 1)
MinButton, MaxButton, and Sizing
 Default border style (2-Sizable) allows user to change
size of form (not a bad idea). To prevent this, change to
1-Fixed Single.
 When do this, Min and Max buttons disappear. Use
MinButton and MaxButton to bring them back.
 User now has all buttons available, but can’t resize form.
Set 1-Fixed Single and
return buttons.
Setting a Form’s Icon
 Each form in your application can have its own icon.
 Program’s icon is the icon of the start up form
 Setting the icon
 Select the form
 Click the Icon property.
 Select the … button and locate your icon
 Icon locations

C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons

Web site links
Using Icon Catcher program

C:\windows\system\shell32.dll

C:\windows\system\pifmgr.dll

C:\windows\system\progman.exe

C:\windows\system\moricons.dll

I:\instructor\107-172\icons

4
Download