pnklphnts
09-05-2003, 06:45 PM
I have been assigned a problem that says that 2 rats are on an island and they have 6 kids every 40 days then those kids after 120 days start having there own kids every thirty days. THen after a year how many rats are there. So i decided to write a program to slove it and impress my teacher. I finished my program but it doesnt seem to work. There is no error messege but when it finishs there are still only two rats. Here is my program:
'// In a Module
Public Type RatType
CreationDate As Long
LastBabyDate As Long
End Type
Public Rat() As RatType
Public Days As Long
'// On Form
Private Sub Form_Load()
ReDim Rat(1 To 2) '// Establish Origanal 2
For I = 1 To 2
Rat(I).CreationDate = -120 '// We want them to start having babies instantly
Next
Days = 365 '// set the number of days
End Sub
Private Sub Calculate_Click()
For D = 1 To Days
For R = 1 To LBound(Rat)
If Rat(R).CreationDate = (D + 120) Then '// If They just matured to baby age then...
Rat(R).LastBabyDate = D '// Set there last baby date
ReDim Preserve Rat(LBound(Rat) To UBound(Rat) + 3) '// We only make 3 New babies to account for the other rat
For I = LBound(Rat) To UBound(Rat) + 3
Rat(I).CreationDate = D
Next
ElseIf Rat(R).CreationDate > (D + 120) Then '// If they've matured before this day
If Rat(R).LastBabyDate = D + 40 Then '// if its time for them to have another group of babies
ReDim Preserve Rat(LBound(Rat) To UBound(Rat) + 3) '// We only make 3 New babies to account for the other rat
For I = LBound(Rat) To UBound(Rat) + 3
Rat(I).CreationDate = D
Next
Rat(R).LastBabyDate = D
End If
End If
Next
Day.Caption = D
Mice.Caption = R
Next
Form1.Caption = "Done"
End Sub
I cannot figure out what is messing up. Thanks for your help.
'// In a Module
Public Type RatType
CreationDate As Long
LastBabyDate As Long
End Type
Public Rat() As RatType
Public Days As Long
'// On Form
Private Sub Form_Load()
ReDim Rat(1 To 2) '// Establish Origanal 2
For I = 1 To 2
Rat(I).CreationDate = -120 '// We want them to start having babies instantly
Next
Days = 365 '// set the number of days
End Sub
Private Sub Calculate_Click()
For D = 1 To Days
For R = 1 To LBound(Rat)
If Rat(R).CreationDate = (D + 120) Then '// If They just matured to baby age then...
Rat(R).LastBabyDate = D '// Set there last baby date
ReDim Preserve Rat(LBound(Rat) To UBound(Rat) + 3) '// We only make 3 New babies to account for the other rat
For I = LBound(Rat) To UBound(Rat) + 3
Rat(I).CreationDate = D
Next
ElseIf Rat(R).CreationDate > (D + 120) Then '// If they've matured before this day
If Rat(R).LastBabyDate = D + 40 Then '// if its time for them to have another group of babies
ReDim Preserve Rat(LBound(Rat) To UBound(Rat) + 3) '// We only make 3 New babies to account for the other rat
For I = LBound(Rat) To UBound(Rat) + 3
Rat(I).CreationDate = D
Next
Rat(R).LastBabyDate = D
End If
End If
Next
Day.Caption = D
Mice.Caption = R
Next
Form1.Caption = "Done"
End Sub
I cannot figure out what is messing up. Thanks for your help.