Dear Members
I am new to this forum and I am very excited to join you and learn from you and I hope able to share from my knowledge. I have a problem with the following code which I extracted from my program. I have been going well until this section of my program and I hope someone is able to assist me.
Basically, this section of my program should calculate selected list items within a loop. I have a feeling I am horribly off track. Could someone please give me an idea where I am going wrong as I am striving to make my programs as efficient as possible. I look forward to your response.
Thanking you in anticipation
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
'Calculate Yacht Charges based on rates
Dim intIndex As Integer = 0
Dim intHrsCharted As Integer
Dim decPrice As Decimal
Dim decItemAmount As Decimal
Dim strMessage As String
Do While intIndex < lstYachtSize.Items.Count
If lstYachtSize.SelectedItem(0) And cboYachtType.SelectedItem(0) Then
decPrice = mdecSize22_RATE
ElseIf lstYachtSize.SelectedItem(1) And cboYachtType.SelectedItem(1) Then
decPrice = mdecSize24_RATE
ElseIf lstYachtSize.SelectedItem(2) And cboYachtType.SelectedItem(2) Then
decPrice = mdecSize30_RATE
ElseIf lstYachtSize.SelectedItem(3) And cboYachtType.SelectedItem(3) Then
decPrice = mdecSize32_RATE
ElseIf lstYachtSize.SelectedItem(4) And cboYachtType.SelectedItem(4) Then
decPrice = mdecSize36_RATE
ElseIf lstYachtSize.SelectedItem(5) And cboYachtType.SelectedItem(5) Then
decPrice = mdecSize38_RATE
ElseIf lstYachtSize.SelectedItem(6) And cboYachtType.SelectedItem(6) Then
decPrice = mdecSize45_RATE
Else
MessageBox.Show("Item is not in the list", "No item match", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
'Calculate extended price and add to order total
If txtHrsCharted.Text <> "" Then 'Not blank
If IsNumeric(txtHrsCharted.Text) Then 'Is numeric
Try
intHrsCharted = CInt(txtHrsCharted.Text)
decItemAmount = decPrice * intHrsCharted
mdecTotal += decItemAmount
lblTotalCharges.Text = FormatCurrency(decItemAmount)
Catch ex As Exception
strMessage = "Calculation error."
MessageBox.Show(strMessage, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else 'Missing data
strMessage = "Enter the quantity."
MessageBox.Show(strMessage, "Data entry erro", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Loop
End Sub