A
avidbug
Guest
Hi guys,
So im a bit stuck at the moment. A program that I have to complete REQUIRES me to use a function in order to return a value (in this case the value would be the furthest distance walked by someone in a walking club, as you'll see in the code) I've consulted google for answers but cannot seem to find any suitable solutions. So within the function FindMax i would need to write a piece of code which would go through each member in the array and find out which one of them has the highest value (so find max procedure i guess). Once that is found the function would return the highest value to me. Thanks in advance for reading.
Structure Information 'Declares the record structure'
'Declares the public variables for use inside the record structure'
Public firstname As String
Public lastname As String
Public distance As Single
End Structure 'Ends the record structure'
'Declares the variables for use inside sub programs'
Dim current_distance As Single
Dim furthest As Single
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim walkingdata(20) As Information 'Declares the array which the information from the members file will be stored in'
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 = (lineparts(2))
'Adds the walkers first name, last name and their total distance walked to seperate listboxes'
ListBox1.Items.Add(walkingdata(20).firstname)
ListBox2.Items.Add(walkingdata(20).lastname)
ListBox3.Items.Add(walkingdata(20).distance)
Loop 'ends the loop'
inputfile.Close() 'closes the members file'
End Sub
Function FindMax(ByVal distance As Single, ByVal inputfile As Single) 'function used to find the maximum distance walked by a member'
Return [furthest]
End Function 'ends the function'
End Class
Continue reading...
So im a bit stuck at the moment. A program that I have to complete REQUIRES me to use a function in order to return a value (in this case the value would be the furthest distance walked by someone in a walking club, as you'll see in the code) I've consulted google for answers but cannot seem to find any suitable solutions. So within the function FindMax i would need to write a piece of code which would go through each member in the array and find out which one of them has the highest value (so find max procedure i guess). Once that is found the function would return the highest value to me. Thanks in advance for reading.
Structure Information 'Declares the record structure'
'Declares the public variables for use inside the record structure'
Public firstname As String
Public lastname As String
Public distance As Single
End Structure 'Ends the record structure'
'Declares the variables for use inside sub programs'
Dim current_distance As Single
Dim furthest As Single
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim walkingdata(20) As Information 'Declares the array which the information from the members file will be stored in'
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 = (lineparts(2))
'Adds the walkers first name, last name and their total distance walked to seperate listboxes'
ListBox1.Items.Add(walkingdata(20).firstname)
ListBox2.Items.Add(walkingdata(20).lastname)
ListBox3.Items.Add(walkingdata(20).distance)
Loop 'ends the loop'
inputfile.Close() 'closes the members file'
End Sub
Function FindMax(ByVal distance As Single, ByVal inputfile As Single) 'function used to find the maximum distance walked by a member'
Return [furthest]
End Function 'ends the function'
End Class
Continue reading...