Public Class Form1 Dim dblresults(9) As Double Dim strtagindex(9) As String Dim strErrMsg As String = "Invalid Input" & vbCrLf & vbCrLf & "Please make sure you have filled in the values properly" Dim strFractional As String = "/" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer = 0 Dim intarrGasLevel As Integer() Dim strarrGasLevel As String() Dim dblGasFraction As Double = 0 ' Check for valid dates and fractions Try If Not IsDate(Me.txtStartDate.Text) Or Not IsDate(Me.txtEndDate.Text) Or Not IsNumeric(Me.txtStartMileage.Text) Or Not IsNumeric(Me.txtEndMileage.Text) Then MessageBox.Show(strErrMsg) Exit Sub End If 'Check for negative mileage and negative date If CInt(Me.txtStartMileage.Text) > CInt(Me.txtEndMileage.Text) Or CDate(Me.txtStartDate.Text) > CDate(Me.txtEndDate.Text) Then MessageBox.Show(strErrMsg) Exit Sub End If If Me.txtGasGauge.Text.Contains(strFractional) Then 'Gas Indicator is a fraction strarrGasLevel = Me.txtGasGauge.Text.Split(strFractional) ReDim intarrGasLevel(strarrGasLevel.GetUpperBound(0)) For Each s As String In strarrGasLevel 'Check for multiple / values in the text and for non-numeric values If i > 1 Or Not IsNumeric(strarrGasLevel(i)) Then MessageBox.Show(strErrMsg) Exit Sub End If intarrGasLevel(i) = CInt(strarrGasLevel(i)) i = i + 1 Next 'Check for a valid fraction If intarrGasLevel(0) > intarrGasLevel(1) Then MessageBox.Show(strErrMsg) Exit Sub End If dblGasFraction = intarrGasLevel(0) / intarrGasLevel(1) Else 'Gas Indicator must not be a fraction If Not IsNumeric(Me.txtGasGauge.Text) Or CInt(Me.txtGasGauge.Text) <> 1 Then MessageBox.Show(strErrMsg) Exit Sub End If dblGasFraction = CDbl(Me.txtGasGauge.Text) End If dblresults = calcrates(CDate(Me.txtStartDate.Text), CDate(Me.txtEndDate.Text), CLng(Me.txtStartMileage.Text), CLng(Me.txtEndMileage.Text), dblGasFraction) displayresults() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub displayresults() For Each c As Control In Me.pnlResults.Controls If c.Tag <> "" Then If c.Tag.ToString.Contains("CHARGE") Or c.Tag.ToString.Contains("PRICE") Then c.Text = dblresults(Array.IndexOf(strtagindex, c.Tag)).ToString("c") Else c.Text = dblresults(Array.IndexOf(strtagindex, c.Tag)) End If End If Next End Sub Private Sub buildindex() Dim i As Integer = 0 For Each s As String In strtagindex Select Case i Case 0 strtagindex(i) = "WEEKS" Case 1 strtagindex(i) = "DAYS" Case 2 strtagindex(i) = "MILES" Case 3 strtagindex(i) = "OVERAGE" Case 4 strtagindex(i) = "GALTOFILL" Case 5 strtagindex(i) = "PRICEPERGAL" Case 6 strtagindex(i) = "BASECHARGE" Case 7 strtagindex(i) = "MILESCHARGE" Case 8 strtagindex(i) = "GASCHARGE" Case 9 strtagindex(i) = "TOTALCHARGE" End Select i = i + 1 Next End Sub Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() buildindex() ' Add any initialization after the InitializeComponent() call. End Sub End Class