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
Ok, so what are the problems? I see several things, some of which probably are only caused by the way the code was pasted into the post, like one of the Subs being wrapped around a function and a property. I do notice these items, though:
1) In the selectedIndexChanged methods, you add something to the combobox. That's a bit unusual. Normally, you read something.
2) You declare price inside the CalculatePrice method, then you appear to try to access it in the Messagebox, which won't work.
3) CalculatePrice is Shared, which isn't technically wrong, but an interesting decision. I don't see it being called anywhere, so it doesn't appear to be doing anything.
4) You attempt to read rmap in the messagebox, as well, but that was a local variable in the property, and therefore can't be read anywhere outside of the property. It is the property itself that should be read.
tnx alot... i am not too familiar with the syntaxes in vb, i have tried everything, i could... i dnt mind if u can pls help further, maybe telling me the syntaxes to achive those...