Creating Select Case blocks with automatic indexing using auto counter

Started by kevin, June 23, 2021, 10:13:31 AM

Previous topic - Next topic

kevin


  Creating Select Case blocks with automatic indexing using auto counter


      This snippet creates a sequence of case statements that are automatically indexes at compile time, allowing you to just drop in new statements  or change the order at will..  Handy if you want to create stack and don't need to know what index is what.



PlayBASIC Code: [Select]
   // preserve of AC value, just in case it's used some place else
constant OLD_AC = ac(0)

// set back to zero
ac= 0


// Automatically index Select Case statement using auto counter
for lp =0 to 10

print "#"+str$(lp)+"loop"
select lp

case Ac(1)
print ">>>>option #0"
case Ac(1)
print ">>>>option #1"
case Ac(1)
print ">>>>option #2"
case Ac(1)
print ">>>>option #3"
case Ac(1)
print ">>>>option #4"
case Ac(1)
print ">>>>option #5"
case Ac(1)
print ">>>>option #7"

EndSelect
next



sync
waitkey


// Restore the Auto counter
ac = OLD_AC




stevmjon

this gets an error message in all 1.65 versions, but works fine in 1.64P4

what version did you write this in, are you using a new secret beta version not yet released to public?
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

kevin


 
Quotewhat version did you write this in, are you using a new secret beta version not yet released to public?

   I have no idea what version i'm using :)   Assumed it was 1.65..   but apparently not