Click here to Skip to main content
15,878,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Read in information for Read button
VB
Private Sub btnRead_Click(sender As Object, e As EventArgs) Handles btnRead.Click
    Dim F As Integer
    Dim P As Integer

    For F = 1 To NumFarmers
        MarsFarmers(F).Name = InputBox("Please enter farmer name" & CStr(F))
        MarsFarmers(F).Workers = CInt(InputBox("Please enter number of workers" & CStr(F)))
        For P = 1 To NumPeriods
            MarsFarmers(F).Profit(P) = CInt(InputBox("Please enter profit of farmer" & CStr(F)))
        Next P
    Next F
End Sub
Posted
Updated 26-Feb-15 10:01am
v2
Comments
Sergey Alexandrovich Kryukov 26-Feb-15 16:36pm    
Please, send me an apple from Mars, when you grow one.
—SA

Arrays start from 0 (zero) to count -1 unless Option Base[^] is set to 1.

See:
Arrays in Visual Basic[^]
 
Share this answer
 
Comments
phil.o 26-Feb-15 16:06pm    
Brilliant! I had forgotten this little specificity :)
My 5.
Maciej Los 26-Feb-15 16:17pm    
Thank you, Phil ;)
Sergey Alexandrovich Kryukov 26-Feb-15 16:35pm    
Ha-ha. A 5.
—SA
Maciej Los 26-Feb-15 16:36pm    
Thank you, Sergey ;)
What is the value of NumFarmers? MarsFarmers array should have this length.

Similarly, what is the value of NumPeriods? The Profit array for each "MarsFarmer" should have this length.

How do you instantiate/initialize these arrays?

Otherwise, the simplest way to solve that is to put a beakpoint at the beginning of the method, press F5 and start debugging line by line by pressing F11; carefully watch for every relevant variable at each step, and confirm it is equal to what you think it should.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900