Title: VB Environment Controls Code Working Environment
1VB EnvironmentControlsCodeWorking Environment
chapter
ONE/TWO
2Getting Started with Visual Basic
- Double-click VB icon on Desktop or use
StartProgramsMicrosoft Visual Basic
6.0Microsoft Visual Basic 6.0 to bring up New
Project dialog box
3VB Development Environment
- Start in the Standard EXE environment
- The Project Window should have a white background
- Form should be displayed in Project Window
- Maximize Project Window
4VB Development Environment
Form Size
Toolbar
Project Explorer
Initial Form Window
Toolbox
Properties Window
Project Window
Form Layout Window
Sizing Handles
5Project Explorer Window
View code
View Object
Change Folders
Used to select the code or object or to change
folders.
6The Toolbox
Label Control
Textbox control
Used to select a control to place on form.
7Adding a Control
- Double-click to add control to center of form
- Can be moved around from there
- Use sizing handles to change size
- Single Click and draw (drag) on form
- Copy and paste (be sure not to make Control Array
- until later)
8The Properties Window
Window Name
Object Box
Properties List Tabs
Scrollable list of properties
Description Pane
Used to change the properties of controls at
design time.
9Important Properties
- Name property identifies the control within the
project (user doesnt see) - Begins with a three-letter prefix
- lbl for label
- txt for text box
- frm for form
- Can include letters, numbers
- txtTextBoxToEnterInfo
- Caption property what user sees on screen
10Textbox
- Use when you want user input
- prefix txt
- Properties
- Text actual text
- Alignment center, left, right
- Multiline true, false
- Example
- txtMessage.Text This is my story.
11Checkbox
- Two options
- Checked True
- Unchecked False
- prefix chk
- Multiple checkboxes may be checked
- Properties
- .Caption actual text
- .Value (default)
- 0 unchecked
- 1 checked
- 2 grayed (unavailable/disabled)
12Option Button
- Presents list of options to user
- Prefix opt
- Choices are mutually exclusive
- Properties
- .Caption actual text
- .Value true/false
13Frame
- Contains sets of checkboxes and option buttons
- prefix fra
- Properties
- .Caption name of frame
- HINT If you want to associate option buttons,
then draw and place frame before instantiating
the buttons. Options within a frame (or form) are
a group within that object.
14Image
- Places images on your form
- prefix img
- Allowable image formats are
- jpg, gif, bmp, ico, etc..
- Properties
- .Stretch true / false (image sized to image
box) - .Visible true / false
15Adding Code to Project
- Code goes in Code Window in event procedure
- Event procedure begins with Private Sub and
ends with End Sub - First Visual Basic Statements -
- End
- lblExample.caption some text
- PrintForm
16Design Time and Run Time
- You are in Design Time when you are designing
the project and adding code - You are in Run Time when you click the Play/Run
icon - You can stop the project and exit Run time by
clicking the Stop icon - You can go to Break Mode by clicking the Pause
icon
17Files in Visual Basic
- All projects in VB have a .vbp (project) file and
at least one .frm (form file) file. - To Save
- FileSave Form As
- FileSave Project As
- Use Save (Disk) icon for periodic saves
- Projects with graphics (and some special text)
also have .frx (binary form) files. - Saved automatically
- Module files have a .bas extension and are pure
code files - no controls or form. - FileSave Module As
18Review
A B C D E
F G H I J
19Graphical User Interface Issues
- What are some ways or things you/user would
expect in a program? - Make things visible
- Minimize required interactions(keystrokes/clicks)
- Anticipate event order
- Good screen design
- What are some issues (technical/human) with
screen design?
20Graphical User Interface Issues
- Keyboard Access
- programmer defined
- Ampersand () identifies accelerator key
- Exit will underline the x and make it the
accelerator key - ALT plus accelerator key - Tooltips
- onscreen, pop-up help
- Property
- .ToolTipText actual text
21Graphical User Interface Issues
- Form Startup Position
- .StartUpPosition 2 (center)
- Tab Order - the order in which the user visits
the commands on the screen using the tab key - based upon concept of focus, TabStop, TabIndex
- focus - the object currently active - SetFocus
- TabStop - whether or not the Tab key stops here
- TabIndex - the Tab rank of a particular object
22TabStops and TabIndex
Label TextBox TabStop
NA TabStop True TabIndex 0
TabIndex 1
Name
23Graphical User Interface Issues
- Command Button Properties
- .Default
- true / false
- Assign the command button event that will be
executed if ENTER is pressed. - .Cancel
- true / false
- assign the command button event that will be
executed when ESC is pressed
24Coding Issues
- VB tracks properties associated with Objects and
provides pull-down menu of available properties - VB has a short cut for assigning multiple
properties of the same object - With ObjectName
- .Property
- .Property
- .Property
- END With
- Shortcuts provide some efficiency in code, mainly
documentation
25Coding Issues
- Dealing with text
- Adding text together is called concatenation
- VB uses (Ampersand) in code to add (join) two
sets of text together. - Example
- txtMyFirstName.text Josh
- txtMyLastName.text Goshen
- txtMyFullName.text txtMyFirstName
txtMyLastName - What is result?
- NOTE ignore the discussion on pages 70-71 about
default properties. In MINS114 you MUST be
explicit in your naming
26Review
- What are the functions of TabIndex and TabStop?
How do they work? - What are three settings of the Font property?
- What are some issues with designing screens for
users? - How would you change the focus of the program to
a command button named cmdStart? - Given that you want the user to choose which
class (freshman, sophomore, junior, senior) they
are in, which type of Object would you use? - What property would you use to set an option
button as selected?