Introduction to Visual Basic Visual Basic RVCC

advertisement
Introduction to Visual Basic
Visual Basic
RVCC
What is Visual Basic?
• An environment for developing Windows
applications
• Components
– A GUI (Graphical User Interface - gooey) designer
• Tools (command buttons, list boxes, text boxes, option
buttons, etc.)
– A programming language
• Qbasic like
– All within an IDE (Integrated Development
Environment)
• design interface, set properties, add code, debug
Topics
•
•
•
•
•
•
•
•
Starting VB
The main VB screen
Event-Driven Programming
Writing a Visual Basic program
Running a Visual Basic program
Saving a project
Opening an existing project
Printing the form(s) and code
Starting VB
•
•
•
•
Start | Microsoft Visual Studio | Visual Basic 6.0
DblClicking on VB shortcut desktop icon
From My Computer
Right click on Start to invoke Explorer
DblClick on Program Files|DblClick on Microsoft Visual
Studio|DblClick on Vb98|DblClick on Vb6
The Main VB Screen
• Design Time vs. Run Time
• Form Window
– The largest window
– This form will become a window at run time
• Toolbox Window
– contains controls (grapical objects) you can add to a
form
– examples: text box, command button, check box, etc.
• Project Explorer (Project Window)
– lists modules (form, standard, etc.) that make up project
– can view code/form of selected module
The Main VB Screen (con’t)
Menu Bar/Toolbar Window
– Menus of: File, Edit, View, Project, Format,
Debug Run, Query, Diagram, Tools, Add-Ins,
Window, Help
– Toolbar: set of Command buttons; convenience tool
for programmer; point mouse to find funtion
• Properties Window
– use this window to set properties of a selected control
• Code Window
– where code is entered
Event-Driven Programming
• Procedural (linear) programming vs. Event-driven
Programming
• Events (at run time)
– single mouse click of command button, form, option
button, etc., ( CLICK event for that control)
– pressing most keys (KEYPRESS event)
– double mouse click (DBLCLICK event for that control)
• Event Handlers (event subroutines)
Private cmdMybutton_Click( )
End Sub
Writing a Visual Basic Program
• Design interface
• Set properties
• Write code
Running a Visual Basic Program
• Either
– Click run button on Toolbar
– Press F5 key
– Click Run|Start on Menu
• Run and test your project
Saving a Project
• Click on the Toolbar button 5th from left (the
one with the diskette icon) or click on the
File|Save Project menu
• A dialog box will appear asking you for the
physical name of your form file(s), and where
you want to save it
• A 2nd dialog box will appear after you take care
of the 1st, asking you for the project name
• If you have only one form file, the name should
be the same for the form file and the project file
• Saving the project again, after the first time will
not invoke dialog boxes
Opening an Existing Project
• Click on the Toolbar button 4rd from left
(the one with the folder icon) or click on
File|Open Project menu or use the hot key
Ctrl/O
• A dialog box will appear requesting the
name of the project and its location
Printing the Form(s) and Code
• Click File|Print menu or use the hot key
Ctrl/P
• A dialog box will appear requesting what
part(s) of the project you want printed
Summary
• Components of Visual Basic
– GUI, programming language, IDE
• Entering the IDE
– menu bar, toolbars, toolbox, form window
• Event Driven Programming
• Developing a VB Project
–
–
–
–
design interface
set properties (design time)
write the code (do the programming)
test (run) the project
• Save the project
• Open an existing project
• Print the interface, properties, and code
Download