Presentation is loading. Please wait.

Presentation is loading. Please wait.

Starting Out with Visual Basic.NET 2 nd Edition Chapter 1 Introduction to Programming and Visual Basic.NET.

Similar presentations


Presentation on theme: "Starting Out with Visual Basic.NET 2 nd Edition Chapter 1 Introduction to Programming and Visual Basic.NET."— Presentation transcript:

1 Starting Out with Visual Basic.NET 2 nd Edition Chapter 1 Introduction to Programming and Visual Basic.NET

2 Starting Out with Visual Basic.NET 2 nd Edition 1.1 Introduction

3 Starting Out with Visual Basic.NET 2 nd Edition With Visual Basic.NET, You May Create applications with graphical windows, dialog boxes, menus, and so on Create applications that work with databases Create web applications and applications that use internet technologies Create applications that display graphics

4 Starting Out with Visual Basic.NET 2 nd Edition 1.2 Computer Systems: Hardware and Software All Computer Systems Consist of Similar Hardware Devices and Software Components

5 Starting Out with Visual Basic.NET 2 nd Edition Organization of a Computer System Central Processing Unit Main Memory Input Device Output Device Secondary Storage

6 Starting Out with Visual Basic.NET 2 nd Edition The CPU Fetches instructions Carries out the operations commanded by the instructions Produces some outcome or resultant information The instructions are part of a program stored as binary numbers

7 Starting Out with Visual Basic.NET 2 nd Edition Main Memory Commonly known as RAM (Random Access Memory) Consists of sequentially numbered storage locations In most contemporary computers, each location can store 8 bits, called a byte RAM is normally a volatile storage medium

8 Starting Out with Visual Basic.NET 2 nd Edition Secondary Storage A nonvolatile storage medium Will hold data without the computer being turned on Usually a disk drive (magnetic storage) Hard disks Floppy disks

9 Starting Out with Visual Basic.NET 2 nd Edition Input Devices A device that receives information from the outside world Keyboard Mouse Scanner

10 Starting Out with Visual Basic.NET 2 nd Edition Output Devices Sends information from the computer to the outside world Display Printer

11 Starting Out with Visual Basic.NET 2 nd Edition Software Programs that run the computer Operating System Software: a set of programs that manages the computer's hardware devices (e.g. Windows 2000) Application Software: a program that makes the computer useful to the user (e.g. Word, computer games, Internet browsers)

12 Starting Out with Visual Basic.NET 2 nd Edition 1.3 Programs and Programming Languages A Program Is a Set of Instructions a Computer Follows in Order to Perform a Task A Programming Language Is a Special Language Used to Write Computer Programs

13 Starting Out with Visual Basic.NET 2 nd Edition What Is a Program?, I 1.Display a message on the screen: "How many hours did you work?" 2.Allow the user to enter the number of hours worked 3.Once the user enters a number, store it in memory 4.Display a message on the screen: "How much do you get paid per hour?" 5.Allow the user to enter an hourly pay rate

14 Starting Out with Visual Basic.NET 2 nd Edition What Is a Program?, II 6.Once the user enters a number, store it in memory 7.Once both the number of hours worked and the hourly pay rate are entered, multiply the two numbers and store the result in memory 8.Display a message on the screen that shows the amount of money earned. The message must include the result of the calculation performed in step 7

15 Starting Out with Visual Basic.NET 2 nd Edition Common Programming Languages BASIC FORTRAN COBOL Pascal C C++ Java

16 Starting Out with Visual Basic.NET 2 nd Edition Methods of Programming Procedural Constructed as a set of procedures (operational, functional units) Object-Oriented Constructed as a set of objects Objects have data elements and perform actions

17 Starting Out with Visual Basic.NET 2 nd Edition Example of an Object This is a GUI object Data includes number-of- hours-worked, hourly-pay- rate, and gross-pay-earned Action is to calculate and display gross-pay- earned, given number-of-hours-worked and hourly-pay-rate

18 Starting Out with Visual Basic.NET 2 nd Edition Event Driven Programming: Events An event is an action that takes place within a program, such as the clicking of a control All Visual Basic.NET controls are capable of detecting various events

19 Starting Out with Visual Basic.NET 2 nd Edition Event Driven Programming: Procedures For every event, there must be an event procedure You will write Visual Basic.NET code that will instruct the computer what actions to take whenever a specific event is triggered

20 Starting Out with Visual Basic.NET 2 nd Edition 1.4 More About Controls and Programming As a Visual Basic.NET Programmer, You Must Design and Create the Two Major Components of an Application: the GUI Elements (Forms and Other Controls) and the Programming Statements That Respond to And/or Perform Actions (Event Procedures)

21 Starting Out with Visual Basic.NET 2 nd Edition Visual Basic.NET Controls As a Windows Operating System user, you are already familiar with many of these controls: Label - A box that displays text RadioButton - A round button that can be selected or not with the mouse Form - A window with other controls within it

22 Starting Out with Visual Basic.NET 2 nd Edition Other Visual Basic.NET Controls CheckBox ComboBox Button GroupBox HScrollBar ListBox TextBox VScrollBar

23 Starting Out with Visual Basic.NET 2 nd Edition Name Property All of the controls have Properties Each Property has a value (or values) Every control has a Name Property The value of the Name Property is what it is called in programs The value of the name property of one of the authors of this book is: Tony

24 Starting Out with Visual Basic.NET 2 nd Edition Examples of Names, I btnCalcGrossPay btnClose txtHoursWorked txtPayRate lblGrossPay Label1 Label2 Label3

25 Starting Out with Visual Basic.NET 2 nd Edition Examples of Names, II Names like Label1 are default names generated by Visual Basic.NET Others are programmer specified using a naming convention: txt… for Text Boxes lbl… for Labels btn… for Buttons

26 Starting Out with Visual Basic.NET 2 nd Edition Gross Pay Calculation Code Private Sub btnCalcGrossPay_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCalcGrossPay.Click Dim grossPay As Single ‘ The next line calculates the gross pay. grossPpay = Val(txtHoursWorked.Text) * Val(txtPayRate.Text) lblGrossPay.Text = FormatCurrency(grossPay) End Sub

27 Starting Out with Visual Basic.NET 2 nd Edition Close Code Private Sub btnClose_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnClose.Click ‘ End the application. End End Sub

28 Starting Out with Visual Basic.NET 2 nd Edition Language Elements Keywords: Words with special meaning to Visual Basic.NET (e.g., Private, Sub ) Programmer-defined-names: Names created by the programmer (e.g., grossPay ) Operators: Special symbols to perform common operations (e.g.: +, -, *, and /) Remarks: Comments inserted by the programmer - not part of the running program

29 Starting Out with Visual Basic.NET 2 nd Edition Language Elements: Syntax Syntax means how things are formed The syntax of Visual Basic.NET specified how the Language Elements can be combined to form a valid program The syntax of the English Language defines how sentences are formed from the parts of speech (nouns, verbs, etc.)

30 Starting Out with Visual Basic.NET 2 nd Edition 1.5 The Programming Process The Programming Process Consists of Several Steps, Which Include Design, Creation, Testing, and Debugging Activities

31 Starting Out with Visual Basic.NET 2 nd Edition Step 1 of Developing an Application Clearly define what the program is to do For example: Purpose: To calculate the user’s gross pay Input: Number of hours worked, hourly pay rate Process: Multiply number of hours worked by hourly pay rate (The result is the user’s gross pay) Output: Display a message indicating the user’s gross pay

32 Starting Out with Visual Basic.NET 2 nd Edition Step 2 of Developing an Application Visualize the application running on the computer and design its user interface

33 Starting Out with Visual Basic.NET 2 nd Edition Step 3 of Developing an Application Make a list of the controls needed Partial list: TypeNameDescription TextBoxtxtHoursWorkedAllows the user to enter the number of hours worked. TextBoxtxtPayRateAllows the user to enter the hourly pay rate LabellblGrossPayDisplays the gross pay, after the btnCalcGrossPay button has been clicked ButtonbtnCalcGrossPayWhen clicked, multiplies the number of hours worked by the hourly pay rate ButtonbtnCloseWhen clicked, terminates the application

34 Starting Out with Visual Basic.NET 2 nd Edition Step 4 of Developing an Application Define the Values of Each Control's Relevant Properties: Control TypeControl NameText Form(Default)"Wage Calculator" Label(Default)"Number of Hours Worked" Label(Default)"Hourly Pay Rate" Label(Default)"Gross Pay Earned" LabellblGrossPay"$0.00" TextBoxtxtHoursWorked"" TextBoxtxtPayRate"" ButtonbtnCalcGrossPay"Calculate Gross Pay" ButtonbtnClose"Close"

35 Starting Out with Visual Basic.NET 2 nd Edition Step 5 of Developing an Application Make a list of methods needed for each control: MethodDescription btnCalcGrossPay_ClickMultiplies the number of hours worked by the hourly pay rate These values are entered into the txtHoursWorked and txt-PayRate TextBoxes The result is stored in the lblGrossPay Text property btnClose_ClickTerminates the application

36 Starting Out with Visual Basic.NET 2 nd Edition Step 6 of Developing an Application Create a pseudocode version of each method: Pseudocode is a combination of English and a programming language For this application: Store Number of Hours Worked times Hourly Pay Rate in grossPay. Store the value in grossPay in lblGrossPay.Text.

37 Starting Out with Visual Basic.NET 2 nd Edition Step 7 of Developing an Application Check the code for errors: Go step by step through the code, running it in your head as though the computer is running it Keep track of where in the code is being executed Keep track of the values of all of the variables

38 Starting Out with Visual Basic.NET 2 nd Edition Step 8 of Developing an Application Use Visual Basic.NET to create the forms and other controls identified in step 3 This is the first use of Visual Basic.NET, all of the previous steps have just been on paper

39 Starting Out with Visual Basic.NET 2 nd Edition Step 9 of Developing an Application Use Visual Basic.NET to write the code for the event procedures and other methods created in step 6 This is the second step on the computer

40 Starting Out with Visual Basic.NET 2 nd Edition Step 10 of Developing an Application Attempt to run the application - find syntax errors Correct any syntax errors found and repeat this step as often as necessary All of the syntax errors must be removed before Visual Basic.NET will create a program that you can actually run on the computer

41 Starting Out with Visual Basic.NET 2 nd Edition Step 11 of Developing an Application Run the application - once all syntax errors are fixed Run the program with a variety of test data Check the results to be sure that they are correct Correct any errors found Repeat steps 10 and 11 as many times as necessary

42 Starting Out with Visual Basic.NET 2 nd Edition 1.6 Visual Studio and the Visual Basic.NET Environment Visual Studio Consists of Tools That You Use to Build Visual Basic.NET Applications

43 Starting Out with Visual Basic.NET 2 nd Edition The Visual Basic.NET Environment, I Design Window Solution Explorer Window Dynamic Help Window Properties Window Docked and Floating Windows Title Bar

44 Starting Out with Visual Basic.NET 2 nd Edition The Visual Basic.NET Environment, II Menu Bar Standard Toolbar Layout Toolbar Toolbox Using Tooltips


Download ppt "Starting Out with Visual Basic.NET 2 nd Edition Chapter 1 Introduction to Programming and Visual Basic.NET."

Similar presentations


Ads by Google