From: MikeD on 24 Jan 2010 14:56 "FM" <spam(a)uce.gov> wrote in message news:uTwzkDSnKHA.1552(a)TK2MSFTNGP05.phx.gbl... > Can someone help me turn this ElseIf logic into a For Next loop: > > If CTR <= 50 Then > Spinner(1) = True > ElseIf CTR > 50 And CTR <= 100 Then > Spinner(2) = True > ElseIf CTR > 100 And CTR <= 150 Then > Spinner(3) = True > ElseIf CTR > 150 And CTR <= 200 Then > Spinner(4) = True > ElseIf CTR > 200 And CTR <= 250 Then > Spinner(5) = True > ElseIf CTR > 250 And CTR <= 300 Then > Spinner(6) = True > ElseIf CTR > 300 Then > Spinner(7) = True > End If > As Rick said, you probably need to answer a few missing details. Assuming this code already does *exactly* what you need, I don't see why you need a For Next loop. What would be looping? Now, if that code DOESN'T do what you need, then you need to tell us what what it is exactly that you need to do. If all you're wanting is to eliminate all those ElseIfs (some people really detest a bunch of ElseIfs), then you'd use a Select Case structure instead. Also note that you don't need an And expression with any of these (you don't need to check any > expressions because the previous < expressions take care of that). Select Case CTR Case Is <= 50 Spinner(1) = True Case Is <= 100 Spinner(2) = True Case Is <= 150 Spinner(3) = True Case Is <= 200 Spinner(4) = True Case Is <= 250 Spinner(5) = True Case Is <= 300 Spinner(6) = True Case Else Spinner(7) = True End Select Of course, the Select Case I wrote is untried and untested air code, so maybe I missed something. <g> -- Mike
From: dpb on 24 Jan 2010 16:06 dpb wrote: .... > 1) set Spinner() = False .... Btw, if make Spinner() fixed-size array (as opposed to dynamic) the Erase statement is useful here to minimize LOC. Erase Spinner ' Set elements of Spinner() = 0 (==False) --
From: FM on 24 Jan 2010 16:24 To clarify: There are seven animations. Each animation is a 3D dice spinning and shows each side of the dice during its spin and 90 frames/images are a full spin. Each animation loops at least a full 90 frames and then continues to spin until the target frame is reached. So each will spin at least 90 frames but no more than 180 frames. Spinner is simply a boolean flag to check when all animations have stopped (ie. Do Until AllSpinners = False...this is a function check that looks at the state of Spinners(1 to 7)). The point of the ElseIf (that is inside the Do Until Loop) is to start each roll of the dice sequentially so that each dice starts spinning when the dice before it has spun 50 frames. This creates a mexican wave kind of effect. By the time the seventh dice is spinning the first 2 or 3 dice have normally stopped so they are not all spinning at the same time, hence Spinners(1 to 7) are not all always true and only all always false once all have spun a full 90 frames + frames to target. CTR is simply a frame counter and can be greater than 300 (but never to extreme more than 7 * 180). Ctr is a whole number currently declared as an integer. I see now I was doing too much testing with the ElseIf. I actually have this working nice but Im trying to make it more flexible so that I can call any dice or any number of dice instead of running all seven animations. Was thinking a For Next would make that more manageable. Perhaps a better approach is needed? Regards FM
From: DanS on 24 Jan 2010 17:15 "FM" <spam(a)uce.gov> wrote in news:#$dKsuTnKHA.1548(a)TK2MSFTNGP02.phx.gbl: > To clarify: There are seven animations. Each animation is a 3D dice > spinning and shows each side of the dice during its spin and 90 > frames/images are a full spin. Each animation loops at least a full 90 > frames and then continues to spin until the target frame is reached. > So each will spin at least 90 frames but no more than 180 frames. > Spinner is simply a boolean flag to check when all animations have > stopped (ie. Do Until AllSpinners = False...this is a function check > that looks at the state of Spinners(1 to 7)). The point of the ElseIf > (that is inside the Do Until Loop) is to start each roll of the dice > sequentially so that each dice starts spinning when the dice before it > has spun 50 frames. This creates a mexican wave kind of effect. By the > time the seventh dice is spinning the first 2 or 3 dice have normally > stopped so they are not all spinning at the same time, hence > Spinners(1 to 7) are not all always true and only all always false > once all have spun a full 90 frames + frames to target. > > CTR is simply a frame counter and can be greater than 300 (but never > to extreme more than 7 * 180). Ctr is a whole number currently > declared as an integer. I see now I was doing too much testing with > the ElseIf. > > I actually have this working nice but Im trying to make it more > flexible so that I can call any dice or any number of dice instead of > running all seven animations. Was thinking a For Next would make that > more manageable. Perhaps a better approach is needed? > > Regards > FM My guess is something like this air-code will do it..... For x = LBound(Spinner) To UBound(Spinner) If CTR > ((x - 1) * 50) Then Spinner(x) = True End If Next If the array was zero-based, this would need to be accounted for, but the above should work with a 1-based array.
From: FM on 24 Jan 2010 19:57 To rephrase this question further. Bear with me :) Im passing the number of dice to spin and which dice to spin. It could be one or seven. The Spinning (D parameter) below refers to the particular dice to spin. In the following code four dice will roll: D1 could be passed for example as 1, D2 as 3, D3 as 5, D4 as 7, so the 1st, 3rd, 5th and 7th dice will spin. Each starts spinning sequentially like a mexican wave as explained in my earlier post using the ElseIf. It works perfectly well but as can be seen it gets a bit drawn out. Is there a more efficient way to do this: Select Case NumDiceToSpin Case 1 'Only roll one Dice Spinning(D1) = True 'D1 refers to the dice to roll between 1 and 7 Case 2 'Only Roll two Dice If CTR <= 50 Then Spinning(D1) = True ElseIf CTR <= 100 Then Spinning(D2) = True End If Case 3 'Only roll three Dice If CTR <= 50 Then Spinning(D1) = True ElseIf CTR <= 100 Then Spinning(D2) = True ElseIf CTR <= 150 Then Spinning(D3) = True End If Case 4 'Only roll four dice If CTR <= 50 Then Spinning(D1) = True ElseIf CTR <= 100 Then Spinning(D2) = True ElseIf CTR <= 150 Then Spinning(D3) = True ElseIf CTR <= 200 Then Spinning(D4) = True End If 'and so on...through to case 7 if more dice are to spin End Select ~ Regards FM
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Creating but not sending a Lotus Notes email Next: Windows hook and control hook |