Results 1 to 4 of 4

Thread: Urgent! pls Help!

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    25

    Urgent! pls Help!

    pls i need help with the code below.. am not sure what i have done.. but i have been with this trying to get to modify it for a longtime now.. pls check it out...
    the application has two combo dropdown list (origin and destination)" i want the two list to contain the values i have in the array as below, 2 buttons (cancel and submit) when the submit button is pressed, the system is going to calculate the price and Bus code of the destination in a messageBox.
    please view attachment for clearer details..
    thank you!
    Code:
    Public Class frmArea1
    
        Private Shared ReadOnly route As String() = { _
            "Holland Circle", "Darbin", "Bugis", "Coronation Street", "Winnard", _
            "Bridgetown", "Gorky", "Interimo", "Bishan", "Woodland Rise" _
        }
    
        Private Sub oringinComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 
    
    oringinComboBox.SelectedIndexChanged
            oringinComboBox.Items.Add(Array.IndexOf(route, "StartLoc"))
        End Sub
        Private Sub destnComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 
    
    destnComboBox.SelectedIndexChanged
            destnComboBox.Items.Add(Array.IndexOf(route, "EndLoc"))
        End Sub
    
        Private Sub submitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submitBtn.Click
    
        Public Shared Function CalculatePrice(ByVal startLoc As String, ByVal endLoc As String) As Decimal
            Private Shared ReadOnly legPrice As Decimal = 1.5D
            Dim startIndex As Integer = Array.IndexOf(route, startLoc)
            Dim endIndex As Integer = Array.IndexOf(route, endLoc)
            Dim price As Decimal = 0D
    
            If (startIndex = -1 OrElse endIndex = -1) Then
                Throw New ArgumentException("One or both of the locations does not exist on the specified route.")
            End If
            If (startIndex = endIndex) Then
                Throw New ArgumentException("Origin and Destination cannot be the same")
            End If
    
            If startIndex < endIndex Then
                price = (endIndex - startIndex) * legPrice
            Else
                price = (route.Length - (startIndex - endIndex)) * legPrice
            End If
    
            Return price
        End Function
    
        Public Shared ReadOnly Property RouteMap() As String
            Get
                Dim rMap As String = route(0)
                For i As Integer = 1 To route.Length - 1
                    rMap &= " BTS " & route(i)
                Next
                Return rMap
    
            End Get
        End Property
         MessageBox.Show("fare: ", price & "bus code:", rMap)
        End sub
    End Class
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width