i really need a quick help with my code. when i debug the program no matter what the numbers in milage and Rate are the result is always 0 and here is my code:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    Dim Milage() As Double
    Dim Dest As String = CStr(txtDestination.Text)
    Dim Rate As Double
    Dim Expense As Single
    ReDim Milage(0 To 1000)

    If IsNumeric(txtMilage.Text) = False Then
        MessageBox.Show("Please enter a correct amount")
        Exit Sub
    End If
    If IsNumeric(txtRate.Text) = False Then
        MsgBox("Please Enter a Numeric Value for rate per mile")
        Exit Sub
    End If
    If Milage(txtMilage.Text) >= 100 Then
        Expense = Milage(txtMilage.Text) * Rate
        txtAmount.Text = CStr(Expense)
    Else : Expense = (Milage(txtMilage.Text) * Rate) / 2
        txtAmount.Text = CStr(Expense)
    End If


End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    txtMilage.Text = ""
    txtRate.Text = ""
    txtAmount.Text = ""
    txtDestination.Text = ""
End Sub

Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
End Sub

End Class

3 Years
Discussion Span
Last Post by C#Jaap

It looks like you're just changing the index of your 'Milage' array, but you have not stored any values in it.


In addition to prixat: Milage(txtMilage.Text) = 0 if isn't set. Then Milage(txtMilage.Text) * Rate is also 0.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.