PDA

View Full Version : More help on LOOKUP tables please.



surfies
- 18th May 2012, 14:29
Can I put a few LABELS in a lookup table? If yes how can I then use the label returned to make the program GOTO that label? GOTO does not work with a variable.
Thanks

Surfies

Darrel Taylor
- 18th May 2012, 15:25
Use ON GOTO or ON GOSUB.

SteveB
- 18th May 2012, 16:13
Do what Darrel says. :)

However, if you need to intermix things in a LOOKUP table, then here is a method to achieve that:


lbl_1stPlace CON $FF
lbl_2ndPlace CON $FE
lbl_3rdPlace CON $FD
lbl_4thPlace CON $FC
My_Index_Var VAR WORD
MY_LOOKUP_Var VAR WORD

'-----------------------------------------------------------------

LOOKUP My_Index_Var, [1,2, lbl_1stPlace,3,4, lbl_2ndPlace ,5,6, lbl_3rdPlace,7,8, lbl_4thPlace,9,10], MY_LOOKUP_Var
SELECT CASE MY_LOOKUP_Var
CASE lbl_1stPlace GOTO 1stPlace
CASE lbl_2ndPlace GOTO 2ndPlace
CASE lbl_3rdPlace GOTO 3rdPlace
CASE lbl_4thPlace GOTO 4thPlace
END SELECT

'-----------------------------------------------------------------
1stPlace:

'-----------------------------------------------------------------
2ndPlace:

'-----------------------------------------------------------------
3rdPlace:

'-----------------------------------------------------------------
4thPlace:

surfies
- 19th May 2012, 15:48
Thanks Darrel and SteveB will try that and let you know.

surfies
- 20th May 2012, 08:54
This ON GOTO command, does it work with PBP 2.32 ?? here is part of the code;

COUNT PORTC.3, 15000, c1 'put pulses in C1

ON c1 GOTO S1,S2,S3,S4,S5,S6,S7,S8 I get a syntax error on this line, do I miss something? S1 to S8 is labels, C1 is defined as a variable.
Thanks.

Acetronics2
- 20th May 2012, 09:13
does it work with PBP 2.32 ???

:confused:

Wowwww !!!

PBP2.32 might be @ least 10 years old ... more than time to upgrade !

my 2.50 version manual does not show ON GOxxx commands ( appears in the v2.60 manual ), sooo ... prepare your :greedy_dollars:

Alain

surfies
- 20th May 2012, 11:54
Aag ja that explains it.
thanks for the help and the quick response, nice to have willing clever people on line.
will just have to make a plan now.

Acetronics2
- 20th May 2012, 13:58
Hi, Surfies

Could have been much easier for us YOU to explain what you physically tried to do ...

I smell some kind of overkill trick here :D

Alain

surfies
- 20th May 2012, 15:24
There is a push button on portc.3, then depending on how many times its pressed, ( up to 8 times ) the program must then jump to that number's sub routine. I hope that make sense.

Acetronics2
- 21st May 2012, 07:30
then depending on how many times its pressed, ( up to 8 times ) the program must then jump to that number's sub routine.


so ...

a "basic" set of IF ... THEN ... GOTO is the trick.

SELECT CASE is the smart way to write it ... but is it available with v 2.32 ???

LOOKUPx is generally used to retrieve constants/values/strings from a table , not label adresses.

Alain

surfies
- 21st May 2012, 11:57
Yes, IF......THEN's is what I'll have to do , thought I could get away without them.
Thanks a lot for all the help.