1 / 20

CS 2340: Programming in VB

CS 2340: Programming in VB. Lab 2 Due 9 pm, Friday, September 27. Button Access Key (Hot Key). Put a “&” in button text The char after “&” is underlined and becomes the Access Key Example Text of btnExit: E X IT (E&XIT) [ALT] + X ==> the same as click btnExit . Form Properties.

jeri
Download Presentation

CS 2340: Programming in VB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 2340: Programming in VB Lab 2 Due 9 pm, Friday, September 27

  2. Button Access Key (Hot Key) 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

  3. Form Properties • Text (title) • FormBorderStyle • WindowsState: Normal, Minimized, Maximized • StartPosition • ControlBox: Control buttons • Minimize, Maximize (restore), Close • MinimizeBox, MaximizeBox

  4. Form Properties • 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

  5. Invoking Event Procedures Private Sub btnExit_Click(...) HandlesbtnExit.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(...) HandlesbtnExit.Click

  6. Function Format and FormatCurrency 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)

  7. Message Box Method Show Overloaded Help Manage Help Settings View Help

  8. Message Box MessageBoxIcon • Asterisk • Error • Exclamation • Hand • Information • None • Question • Stop • Warning

  9. String on Multiple Lines ' 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)

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

  11. Click Event Procedure for btnCompute ‘ 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

  12. Lab 2: Checking Rate 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

  13. Testing GUI Programs 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!

  14. Lab 2: Testing ID • Empty ID Error message • Spaces only Error message • String “CS 2340” Good ID • String “ CS 2340 ” Good ID

  15. Positive and Negative • Zero is a positive number. True False • Zero is a negative number. True False • Zero is a non-positive number. True False • Zero is a non-negative number. True False

  16. Lab 2: Testing Rate (positive) • 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!

  17. Lab 2: Testing Hours (non-negative) • 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!

  18. Lab 2: Testing Gross Pay • Rate: 10 Hours 20 Gross Pay: 200 • Rate: 10 Hours 40 Gross Pay: 400 • Rate: 10 Hours 50 Gross Pay: 500? Gross Pay: 550?

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

  20. Test 1 • 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

More Related