Question: Visual Basic 1 Exercise 10-1: Create the Payment Application This exercise will guide you through the process of creating the Payment application thats described in

Visual Basic 1

Exercise 10-1: Create the Payment Application

This exercise will guide you through the process of creating the Payment application thats described in this chapter. To make that easier for you, youll start from a project that contains the Customer form.

Open the project and prepare the two forms

1. Open the project thats in the C:\VB 2015\Chapter 10\Payment directory. This application contains a single form named Form1.

2. Rename Form1 to frmCustomer. 3. Add a second form named frmPayment to the project.

Design the Payment form

4. Add the controls to the Payment form and set the properties for this form and its controls as described in figures 10-13 and 10-14.

5. Use Tab Order view to set the tab order for the controls on the Payment form if necessary.

Add the code for the Customer form

6. Generate the event handlers for the Load event of the Customer form, for the Closing event of the form, and for the Click event of all three buttons. Then, add the module-level isDataSaved variable, and add the code for these event handlers.

7. Generate an event handler named DataChanged for the SelectedIndexChanged event of the Customer Name combo box. Then, wire this event handler to the TextChanged event of the Payment Method label, and add the code to this event handler so it sets the isDataSaved variable to False.

8. Add the SaveData and IsValidData procedures.

9. Test the Customer form to make sure that it works properly. At this point, you should be able to display the Payment form, but it wont work correctly since you havent added any code to it.

Add the code for the Payment form

10. Generate the event handlers for the Load event of the Payment form and for the Click event of both buttons. Then, add the code for these event handlers.

11. Generate an event handler named Billing_CheckChanged for the CheckChanged event of the Credit Card radio button. Then, wire this event handler to the CheckChanged event of the Bill Customer radio button, and add the code for this event handler.

12. Add the EnableControls, DisableControls, IsValidData, and SaveData procedures.

13. Test the program to be sure that it works as described in figure 10-13. When youre sure it does, close the project.

Code I have so far:

Public Class FrmCustomer

Dim isDataSaved As Boolean = True

Private Sub frmCustomer_Load(sender As Object,

e As EventArgs) Handles MyBase.Load

cboNames.Items.Add("Mike Smith")

cboNames.Items.Add("Nancy Jones")

End Sub

Private Sub DataChanged(sender As System.Object, e As System.EventArgs) Handles cboNames.SelectedIndexChanged,

lblPayment.TextChanged

isDataSaved = False

End Sub

Private Sub BtnSelectPayment_Click(sender As System.Object,

e As System.EventArgs) Handles btnSelectPayment.Click

Dim paymentForm As New frmPayment (This is where I'm getting an error)

Dim selectedButton As DialogResult = paymentForm.ShowDialog()

If selectedButton = DialogResult.OK Then

lblPayment.Text = paymentForm.Tag.ToString

End If

End Sub

Private Sub BtnSave_Click(sender As System.Object,

e As System.EventArgs) Handles btnSave.Click

If IsValidData() Then

Me.SaveData()

End If

End Sub

Private Function IsValidData() As Boolean

If cboNames.SelectedIndex = -1 Then

MessageBox.Show("You must select a customer.", "Entry Error")

cboNames.Select()

Return False

End If

If lblPayment.Text = "" Then

MessageBox.Show("You must enter a payment.", "Entry Error")

Return False

End If

Return True

End Function

Private Sub SaveData()

cboNames.SelectedIndex = -1

lblPayment.Text = ""

isDataSaved = True

cboNames.Select()

End Sub

Private Sub FrmCustomer_FormClosing(sender As System.Object,

e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

If isDataSaved = False Then

Dim message As String =

"This form contains unsaved data." & vbCrLf & vbCrLf &

"Do you want to save it?"

Dim button As DialogResult =

MessageBox.Show(message, "Customer",

MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)

If button = DialogResult.Yes Then

If IsValidData() Then

Me.SaveData()

Else

e.Cancel = True

End If

ElseIf button = DialogResult.Cancel Then

e.Cancel = True

End If

End If

End Sub

Private Sub BtnExit_Click(sender As System.Object,

e As System.EventArgs) Handles btnExit.Click

Me.Close()

End Sub

End Class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!