Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.monash.edu.au IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management.

Similar presentations


Presentation on theme: "Www.monash.edu.au IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management."— Presentation transcript:

1 www.monash.edu.au IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management and Systems

2 www.monash.edu.au 2 Lecture Outline Planning an OOED application in VB TOE Charts Application Development

3 www.monash.edu.au 3 Steps involved in writing a program 1.Define the Problem – Use English 2.Outline the Solution – Write Algorithms 3.Desk Check the Algorithms 4.Plan and Design the User Interface 5.Translate the Algorithms into Code 6.Document and Maintain the program

4 www.monash.edu.au 4 Designing VB.NET Application 1.Identify the tasks the application needs to perform 2.Identify the objects to which you will assign those tasks 3.Identify the events required to trigger an object into performing its assigned task 4.Draw a TOE chart 5.Draw a sketch of the user interface

5 www.monash.edu.au 5 Step 1: Identify the Application’s Tasks What will the user need to enter? What will the application need to calculate? What will the application need to display (screen) and/or print (printer)? Will previous information need to be cleared from the screen? How will the user end the application?

6 www.monash.edu.au 6 Example Tasks Get employee information: >Name, Address, Personnel Number, Hours worked Calculate salary: >(Hours worked * Hourly Rate)- Tax - Deductions Print Salary Slip: >name, personnel number, gross, net End >exit button Clear

7 www.monash.edu.au 7 Step 2: Identify the Objects After completing the Task column of the TOE chart, you then assign each task to an object in the user interface –Use a Text Box for data the user must enter –Use a Label for output produced by program –Use a Button to perform an action

8 www.monash.edu.au 8 Step 3: Identifying the Events Text boxes and Label controls display their contents automatically, so no special event is necessary for them to do their assigned task You will have the buttons perform their assigned tasks when they are clicked by the user For each task you have identified, list the event in the Event column

9 www.monash.edu.au 9 Step 4: Sample TOE Chart

10 www.monash.edu.au 10 Step 5: Design the User Interface Look at the objects in the TOE chart Using pen and paper, sketch the layout of the objects Organize the graphical user interface (GUI) so that the information flows either vertically or horizontally, with the most important information always located in the upper-left corner of the screen

11 www.monash.edu.au 11 GUI Guidelines for building User Interface Info flows vertically/horizontally group related controls – group box, white space command buttons - up to 6, bottom of screen or stacked in corners, most commonly used first meaningful captions on buttons label controls - 1-3 words only align controls [ comprehensive list Zak]

12 www.monash.edu.au 12 The Process of Development Steps: –A. Plan (TOE charts, sketch of user interface, pseudocode) –B. Build user interface –C. Code the Application –D. Test and Debug the Application –E. Write the Documentation

13 www.monash.edu.au 13 Example 1 - Order Form Timber supplier needs an electronic order form which provides customer details, the number of metres of Oak, Pine or Redwood, the cost, and prints a confirmation notice. Oak = $7, Pine = $5, Redwood = $10 per metre To do: –Identify tasks of the application –Objects needed in the application –Events for objects

14 www.monash.edu.au 14 Task, Object, Event TaskObjectEvent 1. Get order information from customer6 text boxes none 2. Calculate total costcmdCost click 3. Display costcmdCost, lblCost click, none 4. Print confirmation noticecmdPrint click 5. Clear screen for next ordercmdClear click 6. End applicationcmdExit click Sketch user interface, naming all objects (even additional ones like labels used next to text boxes) Example: TimberOrder.sln

15 www.monash.edu.au 15 Coding in VB.NET Internal Documentation: –Good practice to leave messages as reminders in the Code window –place apostrophe (‘) before the comment –comments are ignored by VB program

16 www.monash.edu.au 16 End - Today we covered Planning an OOED application in VB TOE Charts + designing user interface Reading –Zak, Chpt 2, p42-70

17 www.monash.edu.au IMS1906 Programming in VB.NET Week 3 – Lecture 2 Assigning values at runtime © Angela Carbone Monash University School of Information Management and Systems

18 www.monash.edu.au 18 Lecture Outline Assigning properties during Run Time Mathematical Operators in-built functions –Val( ), –Format() in-built Method –Focus

19 www.monash.edu.au 19 Assign a value to a property during runtime syntax assignment statement –[Me.]objectName.property = newValue ie. Me.txtCity.Text = "Melbourne” Enables properties to be set or changed during run-time, rather than at design time

20 www.monash.edu.au 20 What do these assignment statements do? –lblLabel.Text = “Name” –txtBox.Text=“” –lblLabel.Text = txtBox.Text

21 www.monash.edu.au 21 Assigning Properties In summary, >properties can be set during design time using the property window >properties can be set or changed during run time using the assignment statement in code (usually in response to the user’s actions)

22 www.monash.edu.au 22 Mathematical Operators ^ exponentiation - negation *, / multiplication, division \ integer division Mod modulus arithmetic +, - addition and subtraction Note that you can use brackets to overcome precedence orders Provided you are dealing with numeric types (not Strings) you can use standard maths operators If strings are involved and you are assigning them to a numeric variable, you must first convert them using Val()

23 www.monash.edu.au 23 Val() Function Most common use for Val() function is in converting Text Box input (a String) into numeric data for mathematical operations Example: Adding two numbers Val(txtNum1.Text) + Val(txtNum2.Text)

24 www.monash.edu.au 24 Why use Val( ) If you don’t use Val(), then + will act as the concatenation operator, so that lblAnswer.Caption = txtNum1.Text + txtNum2.Text = “12” + “34” (concatenate 2 strings) = “1234” (a string) Instead of lblAnswer.Caption = Val(txtNum1.Text) + Val(txtNum2.Text) = Val(“12”) + Val(“34”) (sum of 2 numbers) = 12 + 34 = 46 (a number)

25 www.monash.edu.au 25 Examples: Val Function Val function: Val(“456”)456 Val(“24,500”)24 Val(“123x)123 Val(“$56.88)0 Val(“Abc”)0 Val(“”)0 Val(“25%”)25

26 www.monash.edu.au 26 Format() Function Used to improve the appearance of numbers displayed in your application Syntax: Format(expression, style) Expression specifies the string to format. Style is the name of of VB pre-defined format style (currency, fixed, standard, percent) Eg: lblAnswer.Text= Format (lblAnswer.Text, “Fixed”)

27 www.monash.edu.au 27 Examples –Suppose variable Total = 1221.67856 >Format(Total, “Fixed”) = 1221.68 >Format(Total, “Currency”) = $1,221.68 >Format(Total, “Scientific”) = 1.22E+03 >Format(Total, “True/False”) = True –Suppose variable Total = 0 >Format(Total, “Currency”) = $0.00 >Format(Total, “Scientific”) = 0.00E+00 >Format(Total, “Yes/No”) = No

28 www.monash.edu.au 28 Format Styles General Number - no commas for thousands Currency - dollar sign, comma & cents Fixed - at least 1 digit to left & 2 to right of decimal Standard - like currency but no $ Percent - number x100 with % (& 2 decimals) Scientific - standard scientific notation Yes/No - “No” is 0, otherwise “Yes” True/False - “False” if 0, otherwise “True” On/Off - “Off” if 0, otherwise “On”

29 www.monash.edu.au 29 Using the Focus Method –Focus method allows you to move the focus to a specified control while the application is running. Syntax [Me.]object.Focus() where object is the name of in which you want the focus, and Focus( ) is the name of the method

30 www.monash.edu.au 30 NOTE Assignments change the properties of objects while the application is running (visibility). Methods carry out specific tasks such as printing a form or setting the focus of mouse pointer. Functions manipulate data (arguments) and return a value (adding).

31 www.monash.edu.au 31 Testing and Debugging Testing: –running application with sample data > valid data = expected data >invalid data = unexpected data e.g. entering a letter where a number is expected >data tests should be comprehensive >data tests = 70% of application development time

32 www.monash.edu.au 32 Testing and Debugging Debugging: –process of locating errors in the program –two types of errors: >syntax errors: incorrect language e.g. ‘edn’ instead of ‘end’. VB can locate these. >logic errors: errors in reasoning - will get wrong result even though syntax is correct. Harder to detect.

33 www.monash.edu.au 33 Today’s lecture we covered Assigning values at run time VB in-built functions : –Val() –Format() VB in-built Method –Focus() Testing and Debugging

34 www.monash.edu.au 34 Questions Reading –Zak, Chpt 3 p80, p91-94, p97-100 Stop for a moment and summarise –what you have covered –the main parts of today’s lesson –write down any questions you would like to ask


Download ppt "Www.monash.edu.au IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management."

Similar presentations


Ads by Google