I had a look there and I still don't fully understand how it works.See post #16 in this thread, for some great example code by Hippy:
if b0 = 1 then
gosub Sub1
goto EndOfList
endif
if b0 = 2 then
gosub Sub2
goto EndOfList
endif
if b0 >= 3 and b0 <= 6 then
gosub Sub3
goto EndOfList
endif
EndOfList:
select case b0
case 1
gosub Sub1
case 2
gosub Sub2
case 3 to 6
gosub Sub3
end select
that makes it clearer for me, thanksIt's really just another way of doing repeated "if...then" statements
helps a little, still not got my head around it all.Does that help?
readtemp sens,b1
select case b1 'set pwm according to sensor temperature, PWM % is fan type dependant
case >= 127 goto frost
case >= 81 pwmout pwmdiv4,FET,124,495:high green:goto main '99%
case >= 80 pwmout pwmdiv4,FET,124,490:high green:goto main
case >= 79 pwmout pwmdiv4,FET,124,485:high green:goto main
case >= 78 pwmout pwmdiv4,FET,124,480:high green:goto main
case >= 77 pwmout pwmdiv4,FET,124,475:high green:goto main
case >= 76 pwmout pwmdiv4,FET,124,450:high green:goto main
case >= 75 pwmout pwmdiv4,FET,124,437:high green:goto main
case >= 74 pwmout pwmdiv4,FET,124,425:high green:goto main
case >= 73 pwmout pwmdiv4,FET,124,412:high green:goto main
case >= 72 pwmout pwmdiv4,FET,124,410:high green:goto main
case >= 71 pwmout pwmdiv4,FET,124,400:high green:goto main
case >= 70 pwmout pwmdiv4,FET,124,375:high green:goto main
case >= 69 pwmout pwmdiv4,FET,124,362:high green:goto main
case >= 68 pwmout pwmdiv4,FET,124,350:high green:goto main
case >= 67 pwmout pwmdiv4,FET,124,337:high green:goto main
case >= 66 pwmout pwmdiv4,FET,124,325:high green:goto main
case >= 65 pwmout pwmdiv4,FET,124,312:high green:goto main
case >= 64 pwmout pwmdiv4,FET,124,300:high green:goto main
case >= 63 pwmout pwmdiv4,FET,124,287:high green:goto main
case >= 62 pwmout pwmdiv4,FET,124,275:high green:goto main
case >= 61 pwmout pwmdiv4,FET,124,267:high green:goto main
case >= 60 pwmout pwmdiv4,FET,124,250:high green:goto main
case >= 59 pwmout pwmdiv4,FET,124,225:high green:goto main
case >= 58 pwmout pwmdiv4,FET,124,210:high green:goto main
case >= 57 pwmout pwmdiv4,FET,124,200:high green:goto main
case >= 56 pwmout pwmdiv4,FET,124,195:high green:goto main
case >= 55 pwmout pwmdiv4,FET,124,190:high green:goto main
case >= 54 pwmout pwmdiv4,FET,124,185:high green:goto main
case >= 52 pwmout pwmdiv4,FET,124,180:high green:goto main
case >= 36 pwmout pwmdiv4,FET,124,175:high green:goto main '35%
case <= 35 pwmout FET,off:low green:goto main
endselect
thanksAn example for you
Instead of all those "goto main"s, why not omit them and close withCode:readtemp sens,b1 select case b1 'set pwm according to sensor temperature, PWM % is fan type dependant case >= 127 goto frost case >= 81 pwmout pwmdiv4,FET,124,495:high green:goto main '99% ... endselect
else goto wherever ' if necessary
endselect
goto main
#5, I understand, it is starting to make some sense to me.If you don't understand the second part of post #5, you can worry.
I think the phrase you are looking for "could have been written differently", "could be improved upon", and I would agree but, as the author says, "Why bother, it works fine & has done for years. If it aint broke, don't fix it !!!" and that's an absolutely fine and reasonable response.If you don't understand post #8, don't worry, it's an awful example.
One of the best ways to get to understand how particular commands work is to create a test program and run it in the Simulator, see what it does. For example -I had a look there and I still don't fully understand how it works.
SerTxd( "Starting", CR, LF )
For b0 = 0 To 5
SerTxd( #b0 )
Select Case b0
Case 1 : SerTxd( " - The number is one" )
Case 2 : SerTxd( " - The number is two" )
Case 4 : SerTxd( " - The number is four" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished", CR, LF )
Starting
0
1 - The number is one
2 - The number is two
3
4 - The number is four
5
Finished
Select Case b0
Case >= 4 : SerTxd( " - The number is greater or equal to 4" )
Case >= 2 : SerTxd( " - The number is greater or equal to 2" )
Case >= 1 : SerTxd( " - The number is greater or equal to 1" )
End Select
Select Case b0
Case >= 1 : SerTxd( " - The number is greater or equal to 1" )
Case >= 2 : SerTxd( " - The number is greater or equal to 2" )
Case >= 4 : SerTxd( " - The number is greater or equal to 4" )
End Select
Thanks Hippy, that's what I was looking for, it explains it so I can understand now, thanks.One of the best ways to get to understand how particular commands work is to create a test program and run it in the Simulator, see what it does. For example
SerTxd( "Starting", CR, LF )
For b0 = 0 To 5
SerTxd( #b0 )
Select Case b0
Case 1 : SerTxd( " - The number is one" )
Case 2 : SerTxd( " - The number is two" )
Case 4 : SerTxd( " - The number is four" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished", CR, LF )
For b1 = 0 To 3
Select Case b1
Case >= 4 : SerTxd( " - The number is greater or equal to 4" )
Case >= 2 : SerTxd( " - The number is greater or equal to 2" )
Case >= 1 : SerTxd( " - The number is greater or equal to 1" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished 2nd test", CR, LF )
No, that's not the phrase I was looking for. I wasn't talking about the code, I was talking about the example.I think the phrase you are looking for "could have been written differently", "could be improved upon", and I would agree but, as the author says, "Why bother, it works fine & has done for years. If it aint broke, don't fix it !!!" and that's an absolutely fine and reasonable response.
In illustrating the 'if this then that' nature of a SELECT-CASE it does its job.
Okay, I changed it to 4 loops and I get this, which is a bit different to the first test above.Your second loop is from b1 = 0 to 3, so it never reaches 4
; *******************************
; Written by:
; Function: Testing SELECT CASE
; Target PICAXE: any
; *******************************
SerTxd( "Starting", CR, LF )
For b0 = 0 To 5
SerTxd( #b0 )
Select Case b0
Case 1 : SerTxd( " - The number is one" )
Case 2 : SerTxd( " - The number is two" )
Case 4 : SerTxd( " - The number is four" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished 1st test", CR, LF )
SerTxd( "--------------------------", CR, LF )
SerTxd( "Now using >=", CR, LF )
For b1 = 0 To 4
Select Case b1
Case >= 4 : SerTxd( " - The number is greater or equal to 4" )
Case >= 2 : SerTxd( " - The number is greater or equal to 2" )
Case >= 1 : SerTxd( " - The number is greater or equal to 1" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished 2nd test", CR, LF )
SerTxd( "--------------------------", CR, LF )
SerTxd( "Now using <=", CR, LF )
For b2 = 0 To 4
Select Case b2
Case <= 4 : SerTxd( " - The number is less than or equal to 4" )
Case <= 2 : SerTxd( " - The number is less than or equal to 2" )
Case <= 1 : SerTxd( " - The number is less than or equal to 1" )
End Select
SerTxd( CR, LF )
Next
SerTxd( "Finished 3rd test", CR, LF )
SerTxd( "--------------------------", CR, LF )
Thanks Buzby,Modify the test to show the value of the variable at each step ...
Thank Aries, I understand now, just need to do it a few times to let it sink in.The value b1=3 IS >=2, so it reports accordingly.
In the third test, your loop is b1 = 0 to 4, which is 5 values. Hence, when you have a set of cases which b1 will pass for any value, you get five results.