Link to home
Start Free TrialLog in
Avatar of Karl_mark
Karl_mark

asked on

For...Next Syntax Question VBA

I've taken over some systems at a college and some of the Access databases contain some code which has not been touched for years because "it works" and everyone is too afraid to alter it! Basically, the code takes a student's selected courses and allocates them to classes which is a lot more complex than it initially sounds. Anyway, I can figure out a lot of it, but I am a little perplexed by the code shown below which crops up in similar format throughout:

    For i = 1 To 4: choices(i) = "": pos(i) = 0: groups(i) = 0: Next i

Open in new window


It looks to me like the For...Next loop is being compressed into a single line. Would I be correct? In theory I should be able to expand the code out to a more standard four lines. I just want to make sure that my assumption is correct before messing with code which is nearly two decades old!
ASKER CERTIFIED SOLUTION
Avatar of pdebaets
pdebaets
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peter57r
Yes -it's exactly the same as a vertically presented set of 5 lines .
I assumed the : was a terminator but did a little accdb investigation to see if i could test the loop and output results using a "normal" for/next to get it to run in access 2010, and I get "subscript out of range" on . : pos(i) = 0

Not used arrays in Access for a long time though so it could be my error... SO you might be wise to test loops with ":" in in newer versions of access if you are using an older version and intending to upgrade.
Avatar of Karl_mark
Karl_mark

ASKER

Thanks all. I'll set about making the code more legible. It was written by a mathematician back in around 1992, and I'm trying to fathom how it actually does the allocation; there are lots of number variables thrown in with no commenting, so I'm adding some logfiles to see how it processes the records.
Sounds fun! Good luck :)