PDA

View Full Version : Solved: Kangaroo Problem



SilverBack
12-07-2005, 08:55 PM
Okay here's one you might enjoy. I've got a kangaroo population simulator. I have to have values printed to a worksheet through a UserForm, and a real-time chart. There is one problem, and that is that when I specify a number of months to compute, it computes (Mnth = Mnth - 1). I know this is the root of my problem, but fixing it is a whole different story. If I just code (Mnth = Mnth) and take out the "-1", it errors on me. I've tried a few other things but I hit a brick wall every time.

Thanks!

bodhi
12-07-2005, 11:14 PM
SilverBack,

you have used redim to reallocate storage space for your array variables 'km', 'kf', 'dm', & 'df' to a length of 1 to Mnt.

Further into your code you try and assign a value outside of this array length. try :

ReDim km(1 To Mnt + 1)
ReDim kf(1 To Mnt + 1)
ReDim dm(1 To Mnt + 1)
ReDim df(1 To Mnt + 1)

this will give you one more position in your array and should solve your problem.

http://vbaexpress.com/forum/images/smilies/001.gif

SilverBack
12-08-2005, 08:18 AM
I did what you suggested. The new code is attached. I still fall one short :(

SilverBack
12-08-2005, 08:52 AM
Heheh, talk about being too close to the forest to see the trees! I figured it out. I had to redim mnt (1 to mnt + 1) which allowed me to change the For j=1 to mnt - 1 to For j=1 to mnt

Anyway, thanks again!

bodhi
12-08-2005, 03:56 PM
I should have explained it a little further but i am glad that you solved the probelm.http://vbaexpress.com/forum/images/smilies/023.gif