I need help with the final section of my program

  • Thread starter Thread starter avidbug
  • Start date Start date
A

avidbug

Guest
Hi everyone,

So what i need to do is to start a loop for the members array and find out which members within that array are eligible for a prize. To be eligible for a prize you must have walked at least 70 percent the distance of the furthest distance walked. (so 0.7 * furthest distance) Once all the eligible members have been found, I must print the first names and sir names of these members to an external empty text file. The code below will help explain things better:

ublic Class Form1
Structure information
Public firstname As String
Public lastname As String
Public distance As Single
End Structure

Dim walkingdata(20) As information
Dim AllData As New List(Of information)

Private Sub Caller(sender As Object, e As EventArgs) Handles Button1.Click
Call Receive_Info()
Call FindMax()
Call DisplayMax()
End Sub

Private Sub Receive_Info()

Dim inputfile = IO.File.OpenText("C:\Users\Tristan\Desktop\Computing Assignment\Software Development\members.txt") 'Reads in members file'
Dim Members_array As String() = inputfile.ReadLine().Split(","c)

Do Until inputfile.EndOfStream 'Begins a loop'

Dim lineparts() As String = inputfile.ReadLine.Split(","c)

walkingdata(20).firstname = (lineparts(0))
walkingdata(20).lastname = (lineparts(1))
walkingdata(20).distance = CSng(lineparts(2))

AllData.Add(walkingdata(20))

Loop 'ends the loop'

inputfile.Close() 'closes the members file'

Dim max As information = AllData(FindMax)

ListBox4.Items.Add(max.distance.ToString)

End Sub

Function FindMax()

Dim max As Single = 0
Dim maxID As Integer

For ind As Integer = 0 To AllData.Count - 1
If AllData(ind).distance > max Then
max = AllData(ind).distance
maxID = ind
End If
Next

Return maxID

End Function

Private Sub DisplayMax()

Dim filestring = ("C:\Users\Tristan\Desktop\Computing Assignment\Software Development\results.txt")
Dim objWriter As New System.IO.StreamWriter(filestring)
objWriter.WriteLine("The prize winning members are:")
objWriter.Close()



End Sub

End Class

Continue reading...
 
Back
Top