921 likes | 1.06k Views
Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/. Introduction to Programming Concepts. Visual Basic: an Introduction. Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/. Objectives.
E N D
Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/
Introduction to Programming Concepts Visual Basic: an Introduction Illuminating Computer Science CCIT 4-6Sep http://www.aast.edu/en/colleges/ccit/cs4hs/
Objectives • The audience should be familiar with the Visual Basic Environment. • The audience should be able to build simple Visual Basic Applications. • The audience should learn the precedence rules for writing equations. • The audience should be able to write programs using control structures
Performing a Task on the Computer • Determine Output • Identify Input • Determine process necessary to turn given Input into desired Output
Problem-solving approach like algebra class • How fast is a car traveling if it goes 50 miles in 2 hours? • Output: a number giving the rate of speed in Km per hour • Input: the distance and time the car has traveled • Process: rate = distance/time
Program Planning Tips • Always have a plan before trying to write a program • The more complicated the problem, the more complex the plan must be • Planning and testing before coding saves time coding
Simplified Program development cycle 1. Analyze: Define the problem. 2. Design: Plan the solution to the problem. 3. Choose the interface: Select the objects (text boxes, buttons, etc.).
Program development cycle continued 4. Code: Translate the algorithm into a programming language. Try to avoid jumping straight to this step, which can result in a sloppy solution! 5. Test and debug: Locate and remove any errors in the program. 6. Complete the documentation: Organize all the material that describes the program.
What is Visual Basic? • High Level 4th Generation Programming Language • Object and Event Driven • Visual - Windows Based • Integrated Development Environment or IDE
What is VB Used For? • Most Popular Programming Language • Stand alone programs • Applets that can be run on many different kinds of computers • Customized specialized Applications • E- Commerce • Web based shopping forms and inquiries • User friendly Interface to applications
Also enables user to click on buttons to initiate processing steps. Allows user to use a mouse to click on boxes for text entry. Example Order Entry Screen l l l l l l Used by a computer equipment retail outlet to record data regarding customer orders.
Generations of Computer Languages • 1st - Machine language - 0110 0011 1000 • 2nd - Procedure-oriented languages • FORTRAN - 1954 for scientists and engineers • COBOL - 1959 for business applications • C - 1972 - for UNIX operating systems • 3rd - Object-oriented languages • 4th - Event-driven languages - i.e.VB • 5th - Natural languages i.e. English
Compiler Vs Interpreter • Higher Languages are translated to Machine Language by: • Interpreter • Translates instructions to machine code line-by-line. • BASIC, Quick Basic, Visual Basic • Compiler • Translates the entire program to machine code before running it. • Fortran, C, C++, Visual Basic is also a compiler
What are the Objects in VB? • Pre-programmed Code for: • Command Buttons • Labels • Pictures • Text Boxes • Have both data and procedures wrapped together
What are the Events? • Visual Basic “watches” what the user does • A user activity is called an event • Events include mouse clicks and moves, menu selections, button presses, etc. • Sections of code are only executed in response to an event
What is the Integrated Development Environment (IDE)? Project Explorer (Lists forms) Toolbox (Objects) Form Designer Window Properties Code Editor Forms Layout Window
Visual Basic Environment GUI (Graphical User Interface) - forms and windows that the user sees Property - a characteristic or attribute of an object such as color and size Event - a user action such as clicking a button Code Editor window - editor specially designed to help you when writing code
Visual Basic Environment • Components of the VB design environment (Form view)
Visual Basic Environment • Components of the VB design environment (Code view)
The Code Editor Window Object List Box Procedure List Box Full Module View button Auto List Members
The Code Editor Window Help window Syntax error in Red Procedure view button Error message box
VB Environment: Project Window • The Project Window can be used to navigate between the code and form window for each form / window a project has
VB Environment: Menu Bar • Title bar Menu Bar Toolbar • The Menu Bar consists of 3 elements the • Title Bar, which holds the name of application, default if Microsoft Visual Basic [design] • Menu Bar, this is the link to Visual Basics menu facilities, each menu option drops down into sub-menus • Toolbar, contains icons which give access to the more commonly used commands (which are also available through the menu bar)
VB Environment: Properties Window • Used to set how a control looks andbehaves • Holds its default values
VB Environment: Control Toolbox Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Line Data Control Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shape Image OLE
VB Environment: Context Sensitive Help • Context sensitive help is very useful • Select the item control that you want help on • Press the F1 key F1
The File Menu Project commands Make executable commands Most recent project list Exit command
New Project Open Project Add Project Remove Project Save Project Save Project As Save Component Save Component As Print Print Setup The File Menu
The File Menu Template -particular pattern for a project or a project element; start a project from a template saves time Existing tab - displays VB projects Recent tab - displays most recently accessed projects Project Groups - a collection of several projects
Building Your First Application • There are three primary steps in building a Visual Project: • Place (or draw) controls on the form. • Assign properties to the controls. • Write event procedures for the controls.
Project Files vbp extension = Visual Basic Project • file that tracks all components frm extension = Form file • separate file for each form frx extension = Binary form file • cannot be read by humans vbwextension = Visual Basic workspace
Syntax Boxes • Syntax for a Visual Basic statement is shown in a syntax box • Reserved words are shown in bold • Programmer named words are shown in italics
The Sub Statement Private Subcontrolname_eventname( ) Statements End Sub Where Private is the default procedure type Sub indicates beginning of procedure controlname is name of associated control _ (underscore) required separator eventname is name of corresponding event ( ) set of parentheses is required End Sub indicates end of a procedure
The Sub Statement Example Private Sub cmdCalcTriangle_Click Dim Base As Single Dim Height As Single Dim Height As Single Area = 1 / 2 * (Base * Height) End Sub
Declarations, Variables, and Constants Variable - a uniquely named storage location that contains data that changes during program execution Constant - a uniquely named storage locations that contains data that does not change during program execution