LB Booster
« passing arrays to subs »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 05:01am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: passing arrays to subs  (Read 281 times)
Alincon
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 147
xx Re: passing arrays to subs
« Reply #5 on: Jul 10th, 2017, 2:20pm »

I have made some progress, but still not what I want:
Code:
 'tables.txt now includes the array names on a separate line before the array items
    open "C:\LibBas\_MyLibBas\matchmaker\tables.txt" for input as #tbl
    for j = 1 to 4
        input #tbl, xx$   'get array name      
        print xx$
        call getTable xx$()  
    next
    
   for j = 1 to 7     'checking the arrays
        print j,religion$(j),race$(j),pet$(j),television$(j)  'shows only blanks
   next
   close #tbl  
   end

 sub getTable arr$() 
    input #tbl,x$    'get array item
    n=1
    while word$(x$,n) <> ""
        arr$(n) = word$(x$,n)    'this seems to work 
        print, arr$(n)  'show the array item
        n=n+1
    wend
    end sub

 


revised tables.txt file:
Code:
religion$
Buddist Catholic Muslim Mormon Protestant Other None
race$
White Black Asian Polynesian Hispanic
pet$
Birds Cats Dogs Fish 
television$
Drama Comedy Game Cops Mystery Sci-Fi Reality
 

r.m.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: passing arrays to subs
« Reply #6 on: Jul 10th, 2017, 3:00pm »

Alincon,
I wonder if you actually READ answers?

use
sub getTable arrName$ / function assignStr(byref a$, b$)
from Reply#3.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: passing arrays to subs
« Reply #7 on: Jul 10th, 2017, 4:00pm »

on Jul 10th, 2017, 2:20pm, Alincon wrote:
revised tables.txt file:

I would suggest you step back and consider an alternative way of handling this. For example could not the category names like 'religion', 'race' etc. themselves be data items? Something like this:

Code:
category$(1) = "religion" : category$(2) = "race" : category$(3) = "pet"
count(1) = 7 : count(2) = 5 : count(3) = 4
name$(1,1) = "Buddist" : name$(1,2) = "Catholic" : ... etc.
name$(2,1) = "White" : name$(2,2) = "Black" : name$(2,3) = "Asian" : ... etc.
name$(3,1) = "Bird" : name$(3,2) = "Cat" : name$(3,3) = "Dog" : ... etc. 

Now everything is in three arrays: category$(), count() and name$() and you should be able to do whatever you want using indexing.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »


This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls