So my project works exactly as I want it to. But I have these 2 similar warnings when I Build. I would like to understand and get rid of if possible. Any input would be appreciated.
Warning 1 Variable 'EndMileage' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Users\Owner\Documents\Visual Studio 2008\Projects\Assignment2\Assignment2\CarRental.vb 30 22 Assignment2
Warning 2 Variable 'DaysUsed' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Users\Owner\Documents\Visual Studio 2008\Projects\Assignment2\Assignment2\CarRental.vb 31 36 Assignment2
CODE
Public Class CarRentalCalculator
'delcare constants
Const PerMileRate As Decimal = 0.12D
Const DailyRate As Integer = 15D
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click
'declare variables
Dim StartMileage As Integer, EndMileage, DaysUsed, TotalMiles
Dim TotalCharge As Decimal
'Convert input to values of variables
Try
StartMileage = Integer.Parse(StartMileageBox.Text)
EndMileage = Integer.Parse(EndMileageBox.Text)
DaysUsed = Integer.Parse(DaysUsedBox.Text)
Catch ex As FormatException
MessageBox.Show("Error in input.")
End Try
'Calculate totals
TotalMiles = EndMileage - StartMileage
TotalCharge = (DailyRate * DaysUsed) + (TotalMiles * PerMileRate)
'Display Totals
MilesDrivenBox.Text = TotalMiles.ToString
TotalChargeBox.Text = TotalCharge.ToString
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
'print form
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
'clear fields
NameBox.Clear()
AdressBox.Clear()
StateBox.Clear()
CityBox.Clear()
ZipBox.Clear()
StartMileageBox.Clear()
EndMileageBox.Clear()
DaysUsedBox.Clear()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
End Class