Hello,
I am a newbie and I am learning Visual Basic 2008. My homework is the following:
ublic Class Form1
' This Internet Service provider offers three subscription packages
' to its customers, plus a 20% discount in all packages
' for nonprofit organizations.
' Package A: 10 hours of access for: $ 9.95 per month;
' Additional hours are: $ 2.00 per hour.
' Package B: 20 hours of access for: $ 14.95 per month;
' Additional hours are: $ 1.00 per hour.
'Package C: Unlimited access for: $ 19.95 per month.
' The following class-level constant is used
' to calculate discount.
Const decDiscountRate As Decimal = 0.8D
I created the radio buttons for each package ( they work), and the user has to enter the number of hours using a textbox ( it works after I changed the hours from integer to double).
The display label for TotalAmountDue it works too.
The checkbox captioned ""NonProfit Organization" , it works too.
However, my IF/Then..Else IF statements does not work. The only time it works is when I check package A; then display the $9.95 due.
In addition, I have to use a textbox's validating event to do the validation that hours used in a month cannot exceed 744 (but I will take care of that later).
Could you please tell me, why my loop does not work?
Thank you
Private Sub btnOkay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOkay.Click
' Declare variable
Dim strMessage As String = String.Empty
'The following If..ElseIf..statements test the
' group of radio buttons and copies the first part
' of the message to strMessage.
If radPackageA.Checked = True Then
MessageBox.Show("You selected Package A")
ElseIf radPackageB.Checked = True Then
MessageBox.Show("You selected Package B")
ElseIf radPackageC.Checked = True Then
MessageBox.Show("You selected Package C")
End If
' The following If...Then satements the check box.
If chkNonProfit.Checked = True Then
strMessage = "Non Profit organization"
End If
' Now display the message
MessageBox.Show(strMessage)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' Clear the form, reset the buttons and CheckBox.
radPackageA.Checked = True
radPackageB.Checked = True
radPackageC.Checked = True
txtHoursUsed.Clear()
lblNumberofHours.Text = String.Empty
lblTotalAmountDue.Text = String.Empty
' Return the focus to txtHoursUsed
txtHoursUsed.Focus()
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
' End the application by closing the window.
Me.Close()
End Sub
Private Sub btnCalcAmountDue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcAmountDue.Click
' Declare local variables.
Dim dblHoursUsed As Double ' to hold hours used
Dim dblAmountDue As Double
' Read the value from the TextBox Control.
dblAmountDue = CDbl(txtHoursUsed.Text)
'Calculate the amount due and the 20% discount for (nonprofit)
' using the If/ElseIf statement.
If radPackageA.Checked = True Then
dblAmountDue = 9.95
If (dblHoursUsed > 10) Then
dblAmountDue = 9.95 + (dblHoursUsed - 10) * 2.0
End If
lblTotalAmountDue.Text = CStr(dblAmountDue)
ElseIf radPackageB.Checked = True Then
dblAmountDue = 14.95
ElseIf (dblHoursUsed > 20) Then
dblAmountDue = 14.95 + (dblHoursUsed - 20) * 1.0
If radPackageC.Checked = True Then
dblAmountDue = 19.95
Else(nonprofit) Then
dblAmountDue = dblAmountDue * decDiscountRate
End If
' Display the amount due.
lblTotalAmountDue.Text = CStr(dblAmountDue)
End If
End Sub
Private Sub txtErrorHoursValidation_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtErrorHoursValidation.TextChanged
' Validate the number entered by the user.
If IsNumeric(txtErrorHoursValidation.Text) Then
Dim intHoursUsed As Integer
intHoursUsed = CInt(txtErrorHoursValidation.Text)
If intHoursUsed > 744 Then
lblMessage.BackColor = Color.Red
lblMessage.Text = " Incorrect Data"
End If
End If
End Sub
Private Sub txtErrorHoursValidation_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtErrorHoursValidation.Validating
End Sub
End Class