Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 2 Due 9 pm, Friday, September 27 1. Put a “&” in button text The char after “&” is underlined and becomes the Access Key Example Text of btnExit:

Similar presentations


Presentation on theme: "Lab 2 Due 9 pm, Friday, September 27 1. Put a “&” in button text The char after “&” is underlined and becomes the Access Key Example Text of btnExit:"— Presentation transcript:

1 Lab 2 Due 9 pm, Friday, September 27 1

2 Put a “&” in button text The char after “&” is underlined and becomes the Access Key Example Text of btnExit: EXIT (E&XIT) [ALT] + X ==> the same as click btnExit 2

3  Text (title)  FormBorderStyle  WindowsState: Normal, Minimized, Maximized  StartPosition  ControlBox: Control buttons ◦ Minimize, Maximize (restore), Close  MinimizeBox, MaximizeBox 3

4  Button Click Event ◦ Pressing ENTER when a button has the focus  Multiple buttons on a form  AcceptButton: ◦ Pressing ENTER when no button has the focus  CancelButton ◦ Pressing ESC when no button has the focus  Different ways to invoke the button click event 4

5 Private Sub btnExit_Click(...) Handles btnExit.Click End End Sub ' It will not work if Handles is removed. Private Sub btnExit_Click(...) End End Sub ‘ You could change the Sub’s name Private Sub SubExit(...) Handles btnExit.Click 5

6 txtSum.Text = Format(result, "Currency") txtSum.Text = Format(result, "C") txtSum.Text = Format(result, "General Number") txtSum.Text = Format(result, “n") txtSum.Text = Format(result, "Percent") txtSum.Text = Format(result, "P") txtSum.Text = Format(result, "Standard") txtGrossPay.Text = FormatCurrency(gross) 6

7 Method Show Overloaded Help Manage Help Settings View Help 7

8 MessageBoxIcon  Asterisk  Error  Exclamation  Hand  Information  None  Question  Stop  Warning 8

9 ' Special char vbCrLf MessageBox.Show("Invalid Hours!" + vbCrLf + _ "Hours must be non-negative!", _ "Lab 2", MessageBoxButtons.OK, MessageBoxIcon.Error) ' Special integer Keys.LineFeed ' Run time error MessageBox.Show("Invalid Hours!" + Keys.LineFeed + _ "Hours must be non-negative!", _ "Lab 2", MessageBoxButtons.OK, MessageBoxIcon.Error) ' Special integer Keys.LineFeed ' Cast function Chr MessageBox.Show("Invalid Hours!" + Chr(Keys.LineFeed) + _ "Hours must be non-negative!", _ "Lab 2", MessageBoxButtons.OK, MessageBoxIcon.Error) 9

10 Three Steps Input (from controls) Process (no controls) Output (to controls) 10

11 ‘ Declare variables Dim rate, hours, grossPay, deduction, netPay As Double Dim input As String ‘ Check ID input = txtID.Text.Trim()... ‘ Check Rate input = txtRate.Text.Trim()... ‘ Check Hours input = txtRate.Text.Trim()... ‘ Process ‘ No more controls! ' Display results using controls 11

12 input = txtRate.Text.Trim() If IsNumeric(input) And _ InStr(input, "e", CompareMethod.Text) = 0 Then rate = Convert.ToDouble(input) If rate <= 0 Then MessageBox.Show("Invalid Rate!" + vbCrLf & _ "Rate must be positive!", "Lab 2", _ MessageBoxButtons.OK, MessageBoxIcon.Warning) txtRate.Focus() Exit Sub End If Else MessageBox.Show("Invalid Rate!" + Chr(Keys.LineFeed) & _ "Rate must be a number!", "Lab 2", _ MessageBoxButtons.OK, MessageBoxIcon.Warning) txtRate.Focus() Exit Sub End If 12

13 COURSE OUTCOMES ...  Design, develop and test Visual Basic programs. Users can enter whatever they want and in what order they like. We must make sure the program won’t crash and always work correctly! 13

14  Empty ID Error message  Spaces only Error message  String “CS 2340” Good ID  String “ CS 2340 ” Good ID 14

15  Zero is a positive number. TrueFalse  Zero is a negative number. TrueFalse  Zero is a non-positive number. TrueFalse  Zero is a non-negative number. TrueFalse 15

16  Empty rate Error message  Not a number such as “cs2340” or 234cs Error message  Scientific notation “2e3” Error message  Scientific notation “2E-3” Error message  Number 0 Error message  Negative number such as -1 Error message  Positive number 10.45 Good Rate! 16

17  Similar to testing rate  Negative number such as -1 Error message  Positive number 10.45 Good Rate!  Number 0 Good Hours! Hours can be zero! 17

18  Rate: 10 Hours 20 Gross Pay: 200  Rate: 10 Hours 40 Gross Pay: 400  Rate: 10 Hours 50 Gross Pay: 500? Gross Pay: 550? 18

19 Lab 2: Due 9pm, Friday, September 27 No Grace Time! Test 1: Friday, September 27 Based on Lab1 and Lab2 19

20  Friday, September 27  Lab 206  Create a VB.NET program within 52 minutes  20 points  Open book and notes  Online help available  Your labs available  Do it yourself  No email  No discussion  No credit if no executable file or it does not run  You can ask me for help, but you may lose 3 points each time you receive help  You cannot ask me any questions during the last 15 minutes of the test!  -3 for each run time error 20


Download ppt "Lab 2 Due 9 pm, Friday, September 27 1. Put a “&” in button text The char after “&” is underlined and becomes the Access Key Example Text of btnExit:"

Similar presentations


Ads by Google