Option Explicit On

Option Explicit On

' MyRideHome

' ReplaceThisWithYourName

' 2012-mm-dd Created.

Option Explicit On

Option Strict On

Imports Microsoft.VisualBasic

Imports System

Module MyRideHome

Sub Main()

' Declarations

Const TOLERANCE As Integer = 6' ± the number of seconds to ignore

' when comparing times. If TOLERANCE

' is 6, 120 would be considered equal

' to any value between 114 and 126.

' The file channel numbers and names of the two input files.

Const ROUTE_1_CHANNEL As Integer = 1

Const ROUTE_1_FILE As String = "Route1.txt"

Const ROUTE_2_CHANNEL As Integer = 2

Const ROUTE_2_FILE As String = "Route2.txt"

' The format mask for the output. Arguments:

' 0: The route number (1 or 2).

' 1: The number of times that that route is superior (less than

'TOLERANCE seconds than the other route)

' 2: Excluding equal times, the percentage of comparisons in which

'that route is superior.

Const OUTPUT_MASK As String = "Route {0:D} wins {1:D} times ({2:P})."

Const TOLERANCE_MASK As String = "With a tolerance of {0:D0} seconds,"

' Arrays containing all the times for each route.

' Each array will hold up to a high water mark of data.

Dim route1(500) As Integer

Dim route1HighWaterMark As Integer

Dim route2(500) As Integer

Dim route2HighWaterMark As Integer

' The counts of wins. This is what the whole app is about.

Dim rte1BeatsRte2 As Integer = 0

Dim rte2BeatsRte1 As Integer = 0

' The calculated difference between a time pair.

' Indices into the two arrays.

' The calculated number of non-equal time pairs.

Dim d As Integer

Dim r1, r2 As Integer

Dim total As Integer

' Initialization

' Open the first route file for input, call the procedure that

' loads its array, then close it.

***

***

***

' Open the second route file for input, call the procedure that

' loads its array, then close it.

***

***

***

' Calculation

' The outer loop indexes into the first array's data.

For ***

' The inner loop indexes into the second array's data.

For ***

' Calculate the difference between the two times.

***

' If that difference is not within the tolerance then

' we don't have an "equals" situation. So, ...

If ***

' ... if the time on the 1st route is greater than

' the 2nd route's, then...

If ***

' increment the number of times the 2nd route wins

***

Else

' otherwise increment the number of times the 1st wins

***

End If

End If

Next

Next

' Output

' Calculate the total as the sum of the numbers of wins for each route.

***

' Using the mask, display the tolerance

***

' Using the mask, display the 1st route's channel,

' its number of wins, and its percentage of wins.

***

' Using the mask, display the 2nd route's channel,

' its number of wins, and its percentage of wins.

***

End Sub ' Main()

' A sub procedure, called LoadArray, that reads data from an open channel,

' stores that data in the next location of the array, and increments the

' high water mark.

' The sub procedure receives the following parameters:

' First, an integer parameter, channel, to hold a copy of the channel number.

' Second, a parameter, times(), to hold the address of an integer array

'of times.

' Third, an integer parameter, highWaterMark, to hold the address of

'that array's high water mark.

Sub ***

' Declarations

' Initialization

Dim t As String = String.Empty ' to input data from file

' Initialize the high water mark parameter to -1 meaning there's

' no data in the array.

***

' Calculation

' Loop through the data file while its end hasn't been reached.

Do ***

' Input data from the channel into the string variable "t".

***

' Increment the array's high water mark.

***

' Convert the string to an integer, and store it in the

' array at the high water mark.

***

Loop

End Sub ' LoadArray()

End Module