Documente Academic
Documente Profesional
Documente Cultură
Overview
Programs and Programming Languages Controls and Programming Programming Process Visual Studio
Slide 1- 2
Introduction
Provide graphical windows, dialog boxes, menus Work with databases Use internet technologies Display graphics
Slide 1- 3
1.1
Computer Hardware
Central Processing Unit (CPU) Main memory Secondary storage devices Input devices Output devices
Slide 1- 5
Central Processing Unit (CPU) Fetches instructions from program in main memory
Carries out operations commanded by instructions Each instruction produces some outcome
Slide 1- 7
Main Memory
RAM (Random Access Memory) Sequentially numbered storage locations Holds instructions and data needed for programs currently running Usually volatile (contents lost when power is turned off) Used as temporary storage
Slide 1- 8
Secondary Storage
Secondary storage Nonvolatile storage (contents retained while power is off) Usually a disk drive (magnetic storage)
Slide 1- 9
Input Devices
Slide 1- 10
Output Devices
Examples
Slide 1- 11
Software
Controls processes within computer Manages computer's hardware devices Solves problems or performs tasks needed by users Examples
Application software
1.2
A program is a set of instructions that a computer follows in order to perform a task. A programming language is a special language used to write computer programs.
What Is a Program?
Computer program Set of instructions on how to solve a problem or perform a task Example
In order for a computer to calculate someones gross pay, we must tell computer to perform the following steps
Slide 1- 14
Steps to compute gross pay 1. Display message on screen: "How many hours did you work?" 2. Allow user to enter hours worked 3. Store number in memory 4. Display message on screen: "How much are you paid per hour?" 5. Allow user to enter hourly pay rate 6. Store number in memory
Slide 1- 15
8.
Multiply hours worked by hourly pay rate and store result in memory Display a message on screen with result of previous step
Note: This well-defined, ordered set of steps for solving a problem is called an algorithm
Slide 1- 16
Pseudocode
Start output "How many hours did you work?" input hoursWorked output "How much are you paid per hour?" input hourlyPayRate grossPay = hoursWorked * hourlyPayRate output "You earned ", grossPay Stop
Slide 1- 17
Flowchart
Start
Input hoursWorked
Input hourlyPayRate
Stop
Slide 1- 18
?? ??
gross pay
??
6.
20 25 ??
7.
Multiply hours worked by hourly pay rate and store gross pay in memory
hours worked
hourly pay rate
20 25 500
gross pay
Slide 1- 19
Terms
Slide 1- 20
Algorithm
algorithm noun a set of rules for solving a problem in a finite number of steps, as for finding the greatest common divisor. http://dictionary.reference.com/browse/algorithm
Slide 1- 21
Algorithm (cont.)
In mathematics and computer science, an algorithm is an effective method expressed as a finite list[1] of well-defined instructions[2] for calculating a function.[3] Algorithms are used for calculation, data processing, and automated reasoning. In simple words an algorithm is a step-by-step procedure for calculations. http://en.wikipedia.org/wiki/Algorithm
Slide 1- 22
Computer Program
program noun a. a systematic plan for the automatic solution of a problem by a computer. b. the precise sequence of instructions enabling a computer to solve a problem. http://dictionary.reference.com/browse/program
Slide 1- 23
Terms (cont.)
Machine language Series of 1s and 0s computer understands Programming language Allows programmers to use words instead of numbers Compiler Converts programming language statements to machine language
Slide 1- 25
Slide 1- 26
Language Elements
Words with special meaning to Visual Basic (e.g., Private, Sub) Names created by programmer (e.g., grossPay, btnClose)
Programmer-defined names
Operators
Statements
Instructions made up of keywords, identifiers, and operators Set of programming statements that perform a single task Program documentation inserted by developer and ignored when program runs Begin with ' and continue to end of line
Slide 1- 28
Procedures
Comments
Defines correct use of keywords, operators, and programmer-defined names A program that violates the rules of syntax will not run until corrected Defines correct use of nouns, verbs, etc.
Syntax of English
Slide 1- 29
Methods of Programming
Procedural Constructed as set of procedures (operational, functional units) Each procedure is a set of instructions Object-Oriented Constructed as set of real-world objects
Example of an Object
Graphical User Interface (GUI) object called a form Data include hours worked hourly pay rate gross pay Actions include Calculating gross pay in a method that determines how form reacts
Slide 1- 31
Form elements are objects called controls Sample form has 2 TextBox controls 4 Label controls 2 Button controls A controlss Text property holds the value displayed by the control Text property of left button is Calculate Gross Pay Buttons have methods attached to click events
Slide 1- 32
Visual Basic controls are capable of detecting events Program can respond to an event if programmer writes an event procedure
Slide 1- 33
1.3
As a Visual Basic programmer, you must design and create the applications 1) GUI elements (forms and other controls) 2) programming statements that respond to and/or perform actions (event procedures)
Windows users are familiar with many controls Label - displays text user cannot change TextBox - allows user to enter text Button - performs an action when clicked RadioButton - round button selected or deselected with a mouse click CheckBox - box checked or unchecked with a mouse click Form - window that contains controls
Slide 1- 35
Slide 1- 36
Name Property
All controls have properties Each property has a value (or values) Every control has a Name property Value of Name property is used to reference the control in a program
Controls are assigned default names when created Programmers usually change these names to meaningful names
Slide 1- 37
Examples of Names
Labels use default names (i.e. Label1) Text boxes, buttons, and Gross Pay label play an active roles in program and have been changed
Form1
btnCalcGrossPay
btnClose
Slide 1- 38
Naming Rules
Naming rules Control names must start with a letter Remaining characters may be letters, digits, or underscores
Slide 1- 39
Naming Conventions
txt for Text Boxes lbl for Labels btn for Buttons
Slide 1- 40
' Format gross pay for currency display and assign it to Text ' property of label lblGrossPay.Text = grossPay.ToString("C")
End Sub
Slide 1- 41
Slide 1- 42
1.4
Programming Process
The programming process consists of design, creation, testing, and debugging activities
Slide 1- 44
Visualize application running on the computer and sketch its user interface
Slide 1- 45
Description Allows the user to enter the number of hours worked. Allows the user to enter the hourly pay rate Displays the gross pay, after the btnCalcGrossPay button has been clicked When clicked, multiplies the number of hours worked by the hourly pay rate When clicked, terminates the application
Description for Number of Hours Worked TextBox Description for Hourly Pay Rate TextBox Description for Gross Pay Earned Label A form to hold these controls
Slide 1- 46
Slide 1- 47
btnClose_Click
Slide 1- 48
Create pseudocode or flowchart of each method Pseudocode is an English-like description in programming language terms
Compute grossPay as numberOfHoursWorked times hourlyPayRate Assign to lblGrossPay.Text the value in grossPay
Slide 1- 49
Start
End
Slide 1- 50
Desk check code for errors Read flowchart and/or pseudocode Step through each operation as if you are the computer Use paper to jot down values of variables and properties as they change Verify that expected results are achieved
Slide 1- 51
Use Visual Basic to create GUI (Graphical User Interface) Forms and other controls identified in step 3
Note: This is first use of Visual Basic. All previous steps have just been on paper. In this step you develop portion of application that the user will see.
Slide 1- 52
Use Visual Basic to write code for Event procedures Other methods created in step 6
Note: This is second use of Visual Basic. In this step you develop methods behind click events for buttons. This portion of application the user will not see.
Slide 1- 53
Attempt to run the application - find syntax errors Correct any syntax errors found Repeat this step as many times as needed
Note: All syntax errors must be removed before Visual Basic will create a program that actually runs
Slide 1- 54
Run application using test data as input Run the program with a variety of test data Check results to be sure that they are correct (Incorrect results are referred to as runtime errors) Correct any runtime errors found Repeat steps 10 and 11 as often as necessary
Slide 1- 55
1.5
Visual Studio consists of tools that you use to build Visual Basic applications
Visual Studio Integrated Development Environment (IDE) Provides tools needed to create, test, and debug software applications
Form designer to create the user interface Code editor and compiler
Slide 1- 57
Tutorial 1-4 introduces elements of the IDE Customizing the IDE Windows
Design design and create a form Solution Explorer shows files in solution Properties modify properties of an object Dynamic Help handy reference tool Toolbox objects used in form design
Toolbar icons for frequently used functions Tooltip short description of icons purpose
Slide 1- 58
Creating a VB Application
To create an application Open Visual Studio Create a New Project Create a New VB .NET Windows Application Add Controls to Design Window Add Code for Event Procedures Build Project Run Code View Results
Slide 1- 59
Slide 1- 60
New Project
Design Window
Solution Explorer
Design Window Toolbox Properties Window
Environment Toolbox Design Window Solution Explorer Window Properties Window Dynamic Help Window Docked and Floating Windows
Slide 1- 65
Toolbox
Properties Window
Code Window
Build Solution/Project
Run/Start Debugging
Sample Run
Code
' Compute Wages Code Private Sub btnCalcGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcGrossPay.Click ' declare variable to hold computed wages Dim hoursWorked As Double Dim hourlyRate As Double Dim grossPay As Double
Double.TryParse(txtHoursWorked.Text, hoursWorked) Double.TryParse(txtHourlyPayRate.Text, hourlyRate) ' compute gross pay based on hours worked and hourly pay rate grossPay = hoursWorked * hourlyRate
' display gross pay lblGrossPayEarned.Text = grossPay.ToString("c") End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click ' close form to end application Me.Close() End Sub
Slide 1- 71
Code
End Sub
Slide 1- 72
Summary
Programs and Programming Languages Controls and Programming Programming Process Visual Studio
Slide 1- 73