Re: Previous / Next Function
From a cursory look at your code it appears that valid x values range from 0 to amount(x) - 1.
Also if amount is an array I suspect this is an error. Isn't there really just one amount involved here?
In your "wrap around" logic I think you need to test against amount(x) - 1 (or just a non-array amount - 1) in the forward case, and against having reached 0 when going backward (i.e. "previous").
Re: Previous / Next Function
although im very grateful for your help
i will admit that i dont fully understand what you mean =\
if it is possible, could you perhaps "dumb" it down so to speak haha
Re: Previous / Next Function
Is what you posted, your actual code? If so, add Option Explicit to the top of your form & press Ctrl+F5. Any errors? If so those, need to be addressed first.
Second. What is X? You use it quite often but it is not declard anywhere. Not only that, but you are freely using it as a loop variable, some input type variable and an array index -- this is going to cause you issues.
Third, as dilettante pointed out, why do you have amount() as an array? Your app will only have one amount value, ever, correct? Therefore, make it easier on yourself and declare Amount as a Long, not as an array.
Re: Previous / Next Function
I see
i have got option explicit on my coding, but i just missed it out by accident
I have declared X in a module as my array index, as you rightly said using it for a loop variable caused me issues, i changed the loop variable to "pos" instead.
i used "amount(x)" because if you look at the first set of coding, "amount(x)" represents the amount of storms the user is watching, so i figured that using it here would cause the loop to go around the amount of storms the user entered.
but i have gotten rid of Amount(x) and declared is as long.
again getting input and displaying the data works fine. Its just this part which seems to go wrong.
again thanks for the help
Re: Previous / Next Function
For pos = 0 To amount
If pos < amount Then
pos = amount + 1
Else
pos = 0
End If
this is what i have now, it still wont work however
Re: Previous / Next Function
You are not using a For:Next loop properly. pos will always be less than amount until the loop terminates natually. It starts at zero and ends after it equals amount. You do not manually increment pos, the For:Next does that automatically.
Recommend this: Declare form-level variable lStep As Long
Clicking next:
Each time next is clicked increment lStep. If it is > Amount, then reset it back to first step or abort whichever is appropriate.
Clicking previous:
Each time previous is clicked, decrement lStep. If it is < first step then abort or set to Amount (last step) whichever is appropriate