Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Aug 11th, 2006, 4:41 AM   #1
jaybird01
Newbie
 
Join Date: Aug 2006
Posts: 4
Rep Power: 0 jaybird01 is on a distinguished road
VB.NET: Loops - calculate selected items

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
jaybird01 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:29 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC