For next... Case?

Blitz3D Forums/Blitz3D Beginners Area/For next... Case?

Yahfree(Posted 2007) [#1]
Heres a noob question, this won't work:


Select Statement
Case 1: ;do somthing

Case 2: ;do somthing

For i=3 to 10
Case i
next
End Select



see i have a veriable that can change, and i need a way to check a way to create multible case statements depending on what this veriable says..


in the above code i hoped to create 7 Cases numbering 3-10

but it doesnt work like that, any ideas/workarounds? i'm stumped.


H&K(Posted 2007) [#2]
Select True
Case Statement =1
Case Statement =2
Case Statement>= 3 And Statement<= 10
In brief, the Cases have to meet the Select to happen, now if you do it the way you had, then a case has to equal your Statement. If on the other had we say that the Select is "True", then any case that "Is true" is run.

So yours
Select Statement
Case 1......... If Statement = 1 then
Case 2......... If Statement = 2 then

In mine
Select True
Case Statement =1 ........ If (Statement =1) = true then
Case Statement =2 ........ If (Statement =2) = true then
Case Statement>= 3 And Statement<= 10 ........ if (Statement>= 3 And Statement<= 10) = True then

You use the one you are doing for cases which are discreate, and the second when they are not


Yahfree(Posted 2007) [#3]
looking back i wasnt very clear(i tried to simplefy it)

heres my problem exactly:

i'm using WB3D to create some buttons and i'm creating a button on each tabber panel, the number of tabber panels can change:

......
......
......
......

Dim buttons(number_of_panels)

For i=0 To number_of_panels-1

	buttons(i) = WB3D_CreateButton("test",x,y,w,h,Panel(i),style)
	
Next

......
......
......
......

Case WB3D_EVENT_GADGET

	selected = WB3D_EventSource()
	Select selected
	
		;PROBLEM!! SOMEHOW NEED TO CREATE A CASE FOR EACH BUTTON!
		Case buttons() ;???????????????????????????????????
		;HELPHELPHELPHELPHELP
		
......
......
......
......
......
......
......


i'll look into what you said H&K, thanks for the reply


H&K(Posted 2007) [#4]
I havent used WB3D , but if the Buttons are created one after the other, then there is a possibility that their IDs are always going to be in Series, and then you can say (For example) Buttons(3)+1 = Buttons(4), if so then what I posted would still be of use
Code Selected>=Buttons(3) and Selected <=Buttons(10)



Yahfree(Posted 2007) [#5]
i'll try that, thanks!


doesnt seem to work:

Case selected >= buttons(0) And selected <= buttons(number_of_towers-1)



TomToad(Posted 2007) [#6]
You could also possibly use Default depending on what you are trying to do:
Select Statement
   Case 1: ;Do Something when Statement = 1
   Case 2: ;Do something when Statement = 2
   Default: ;Do something in all other cases
End Select



Yahfree(Posted 2007) [#7]
wouldnt work, it would always do the button action every loop if that was the case.

i edited my post above, it doesnt work (H&K's idea)

hmm, still brain storming :D thanks for the reply tom


H&K(Posted 2007) [#8]
And you definatly had Select True?

Anyway, can you
For i = 0 to number_of_towers-1
print buttons(i)
next
A couple of times, And post the results


Yahfree(Posted 2007) [#9]
i think the problem is buttons is an array of handles pointing to buttons i created, normaly i'd go like this:

Case Buttons(0)
Case Buttons(1)
...
...
...


but the number of buttons can change, so it would sometimes give me array out of bounds.

thats why i need some way to control how many case statements are created...

oh and heres the results from that test:

197460
197458
263130


and guess what? their random! :) Win API handle id's :(


H&K(Posted 2007) [#10]
Ah well, you could just use a for loop and If statments.


Yahfree(Posted 2007) [#11]
i think it has to be a select statement, i'll mess with it


Yahfree(Posted 2007) [#12]
Ooh, thanks for bringing that for/if combo up, i ignored it because i thought it had to be Select-case, but messing with it i found a way to blend in ifs/selects now it works!

thanks H&K