LB Booster
Programming >> Liberty BASIC language >> Printing array issue
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1506773288

Printing array issue
Post by flotulopex on Sep 30th, 2017, 12:08pm

Hi,

I'm stuck in something obviously simple...but I can't see the mote in my eye.

Code:
Counter = 0
L1$ = "AAA"     : L1 = LEN(L1$)
L2$ = "BBBBB"   : L2 = LEN(L2$)
L3$ = "CCCCCCC" : L3 = LEN(L3$)
FOR Counter = 1 TO 3
    PRINT Counter, L(Counter)
NEXT Counter 


How do I make L(Counter) show up correctly in the list instead of "0"?
Re: Printing array issue
Post by Rod on Sep 30th, 2017, 2:53pm

Code:
Counter = 0 '? Counter is set to 1 when you enter the for next loop
dim L(3) 'create the array you intend to use
'store the length to this array, not L1,L2,L3
L1$ = "AAA"     : L(1) = LEN(L1$)
L2$ = "BBBBB"   : L(2) = LEN(L2$)
L3$ = "CCCCCCC" : L(3) = LEN(L3$)
FOR Counter = 1 TO 3
    PRINT Counter, L(Counter)
NEXT Counter
 

Re: Printing array issue
Post by Richard Russell on Sep 30th, 2017, 3:10pm

on Sep 30th, 2017, 12:08pm, flotulopex wrote:
How do I make L(Counter) show up correctly in the list instead of "0"?

Another way:

Code:
Counter = 0
L1$ = "AAA"     : L1 = LEN(L1$)
L2$ = "BBBBB"   : L2 = LEN(L2$)
L3$ = "CCCCCCC" : L3 = LEN(L3$)
FOR Counter = 1 TO 3
    PRINT Counter, EVAL("L";Counter)
NEXT Counter 

Fewer changes from the original than Rod's solution, but using EVAL like this isn't recommended.

Richard.

Re: Printing array issue
Post by flotulopex on Oct 1st, 2017, 08:45am

Thanks a lot guys wink