Visual Basic Week 2 http msdn 08 eacademy

Visual Basic Week 2 http: //msdn 08. e-academy. com/tamucc_mis

Types of Errors • Syntax errors • Logic errors • Run-time errors

Syntax Errors • Equivalent to grammatical errors in English – For example: You green the computer. • Does not make sense to use an adjective instead of a verb in the sentence above • Likewise if the VB complier cannot understand a statement you have committed a syntax error

Syntax Error • Results from mistyping a word or forming a bad expression in the code • Examples: – 524+ + 62. 55 – If Number == 2 Number = 6 – Label 1. tuxt = “Hehe!” – Labelone. text = “Hoho!”

Syntax Errors • Example Data Type Error: – Valid statement: label 1. Top = 20 – Syntax error: label 1. Top = “hoho” • VB can automatically catch syntax errors • VB places a squiggly line under “hoho” to mark the error and a display box explains the error when the cursor is placed over the error

Syntax Errors • Use the Option Strict On statement to catch the data type errors • Insert at the beginning of the program • Syntax error are easy to find and correct because the development systems finds them for you

Logic or Semantic Errors • If you tell VB to do something that you did not intend of it to do • Example: – You multiply two variables when you meant to divide them – Results in an incorrect result but no error message • Logic errors are errors of meaning • Sometimes can be difficult to catch

Logic or Semantic Errors • Sometimes can be difficult to catch • Often need to step patiently through the execution of the program

Run Time Errors • Are detected when the program executes • Example: a user enters illegal data – Types a string when a number is expected • Running a payroll program, the user entered “ten” as the hours worked instead of 10, when the computer tried to multiply the pay rate by “ten” the following error message displays

Errors • The key to handling errors is to catch them and correct them in the early stages of the development

User Interface • Visual Studio development system automatically generates the VB code to create your user interface. Part of the code for the first application Private Sub Initialize. Component() Me. Button 1 = New System. Windows. Forms. Button() Me. Suspend. Layout() ' 'Button 1 ' Me. Button 1. Font = New System. Drawing. Font("Microsoft Sans Serif", 14. 25!, System. Drawing. Font. Style. Regular, System. Drawing. Graphics. Unit. Point, CType(0, Byte)) Me. Button 1. Location = New System. Drawing. Point(66, 76) Me. Button 1. Name = "Button 1" Me. Button 1. Size = New System. Drawing. Size(160, 120) Me. Button 1. Tab. Index = 0 Me. Button 1. Text = "You have Clicked on the button!" ' 'Form 1 ' Me. Auto. Scale. Base. Size = New System. Drawing. Size(5, 13) Me. Client. Size = New System. Drawing. Size(292, 273) Me. Controls. Add. Range(New System. Windows. Forms. Control() {Me. Button 1}) Me. Name = "Form 1" Me. Text = “My Application" Me. Resume. Layout(False) End Sub

User Interface • When you write your program, you are actually creating a new class, and when you run the program, VS. NET automatically creates an instance of that class and executes it. That new object is called Me, and it contains a Button called Button 1. This automatically generated code assigns values to the properties of Button 1 that I changed while creating the user interface. If you do not change the value of a property, it inherits a default value automatically.

User Interface (UI) Design • UI is a very important factor in the design of an application • UI is how the user interacts with the application • Designing a good user interface which is easy to use and understand is crucial for a successful application • A well designed user interface makes it easy and simple for the target audience to understand use • a poorly designed user interface will be hard to understand use and can lead to distraction and frustration Source: http: //www. startvbdotnet. com/forms/design. aspx

User Interface (UI) Design • Human Factors Goals – Provide an interface that is intuitive to the users – Provide the user with the easiest interaction possible – Help the users complete their tasks

UI Principles • • Simplicity Positioning of Controls Consistency Aesthetics Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Simplicity • The user interface should allow the user to complete all the required tasks by the program quickly and easily • Not crowded with controls • No flashy and/or unnecessary images • Simple and complete = user friendly Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Positioning of Controls • Should reflect their importance • Match the program flow (i. e. , data entry form a submit button at the bottom) Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Consistency • Should consistent look through out the application • Before developing an application, you need to plan and decide a consistent visual scheme for the application that will be followed throughout the application • Using of particular fonts for special purposes, using of colors for headings, use of images, etc are all part of consistency Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Aesthetics • An application should project an inviting and pleasant user interface • Color – Use of color is one way to make the user interface attractive to the user. The color which you select for text and back-ground should be appealing. Care should be taken to avoid gaudy colors that are disturbing to the eye, for example, black text on a red background. Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Aesthetics • Fonts – The fonts which you use for text should also be selected with care. Simple, easy-to-read fonts like Verdana, Times New Roman should be used. Try to avoid bold, strikeout text in most parts of the application. Use of bold, italics and other formatting should be limited to important text or headings. Source: http: //www. startvbdotnet. com/forms/design. aspx

UI Principles - Aesthetics • Images – Images add visual interest to the application. Simple, plain images should be used wherever appropriate. Avoid using flashing images and images that are not necessary but are used only for show off Source: http: //www. startvbdotnet. com/forms/design. aspx

Poor UI Design Example Source: http: //www. startvbdotnet. com/forms/design. aspx

The Programming Process • The Programming Process Consists of Several Steps, Which Include Design, Creation, Testing, and Debugging Activities

Step 1 of Developing an Application • Clearly define what the program is to do • For example, the Wage Calculator program: – 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 (result is the user’s gross pay) – Output: Display a message indicating the user’s gross pay

Step 2 of Developing an Application • Visualize the application running on the computer and design its user interface

Step 3 of Developing an Application • Make a list of the controls needed Type Text. Box Label Name txt. Hours. Worked txt. Pay. Rate lbl. Gross. Pay Button btn. Calc. Gross. Pay Button btn. Close 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 btn. Calc. Gross. Pay button has been clicked When clicked, multiplies the number of hours worked by the hourly pay rate When clicked, terminates the application Label Form (default) Description for Number of Hours Worked Text. Box Description for Hourly Pay Rate Text. Box Description for Gross Pay Earned Label A form to hold these controls

Step 4 of Developing an Application • Define values for each control's relevant properties: Control Type Form Label Text. Box Button Control Name (Default) lbl. Gross. Pay txt. Hours. Worked txt. Pay. Rate btn. Calc. Gross. Pay btn. Close Text "Wage Calculator" "Number of Hours Worked" "Hourly Pay Rate" "Gross Pay Earned" "$0. 00" "" "" "Calculate Gross Pay" "Close"

Step 5 of Developing an Application • List the methods needed for each control: Method btn. Calc. Gross. Pay_Click Description Multiplies hours worked by hourly pay rate These values are entered into the txt. Hours. Worked and txt. Pay. Rate Text. Boxes Result is stored in lbl. Gross. Pay Text property btn. Close_Click Terminates the application

Step 6 of Developing an Application • Create pseudocode or a flowchart of each method: – Pseudocode is an English-like description in programming language terms Store Hours Worked x Hourly Pay Rate in sng. Gross. Pay. Store the value of sng. Gross. Pay in lbl. Gross. Pay. Text. – A flowchart is a diagram that uses boxes and other symbols to represent each step Start Multiply hours worked by hourly payrate. Store result in sng. Gross. Pay. Copy value in sng. Gross. Pay to lbl. Gross. Pay text property End

Step 7 of Developing an Application • Check the code for errors: – Read the flowchart and/or pseudocode – Step through each operation as though you are the computer – Use a piece of paper to jot down the values of variables and properties as they change – Verify that the expected results are achieved

Step 8 of Developing an Application • Use Visual Basic to create the forms and other controls identified in step 3 – This is the first use of Visual Basic, all of the previous steps have just been on paper – In this step you develop the portion of the application the user will see

Step 9 of Developing an Application • Use Visual Basic to write the code for the event procedures and other methods created in step 6 – This is the second step on the computer – In this step you develop the methods behind the click event for each button – Unlike the form developed on step 8, this portion of the application is invisible to the user

Step 10 of Developing an Application • Attempt to run the application - find syntax errors – Correct any syntax errors found – Syntax errors are the incorrect use of an element of the programming language – Repeat this step as many times as needed – All syntax errors must be removed before Visual Basic will create a program that actually runs

Step 11 of Developing an Application • Run the application using test data as input – – – Run the program with a variety of test data Check the results to be sure that they are correct Incorrect results are referred to as a runtime error Correct any runtime errors found Repeat this step as many times as necessary
- Slides: 34