Re: TIB: String Arrays, GOSUB


[Prev][Next][Index][Thread]

Re: TIB: String Arrays, GOSUB



String arrays are fairly simple to use on the 85 and 86

METHOD1:  (a read and write array)
:int 9rand\->\R
:"zero one  two  threefour five six  seveneight"\->\S
:Disp sub(S,5R+1,5

OR

METHOD2:  (a read only array)
:int 9rand\->\R
:Disp sub("zero one  two  threefour five six  seveneight",5R+1,5

Either way will work the same, you just need to use the first way if you
use the same string more than once.

If you're wanting a way on the 82, sorry there isn't one(no string
variables, just string literals).

5 is the string width and R is the index 0 to 8, and 1 is added since
strings start at 1.  It's a little more complicated to store stuff to the
string, but not much.  You just have to make sure that the string you're
storing is 5 characters long(or whatever suits your purposes).  ex:

This _MUST_ have a space buffer on each end if you want to store to the
first or last places since you can't add null strings (gives an error
dimension or something) to anything.  This is why the offset is now 2
(not 1 like above).

:" zero one  two  threefour five six  seveneight "\->\S
:4\->\R
:Disp sub(S,5R+2,5
                             four
:"fore"\->\N
:5(R+1)+2\->\A
:sub(S,1,5(R-1)+2)+sub(N+"    ",1,5)+sub(S,A,1+lngth S-A\->\S
:Disp sub(S,5R+2,5
                             fore

I don't know if this works correctly since I haven't tested it, but you
get the basic idea.  If you get into multidimensional string arrays,
that's where it gets a little more complicated, but I used that in a
vocabulary studying program I wrote a few months ago and it works great. 
If you would like to check it out, it's on my webpage (see my sig).

On Tue, 21 Oct 1997 15:44:04 -0700 Peter Sahlstrom
<petes@technologist.com> writes:
>     I know it's possible to do something similar to
>what is done in lines 20 & 40 by calling another
>program, and having the called program have a RETURN
>statement at the end, but it would simplify  my
>programming greatly if I was able to do in-program
>subroutine calls.

I guess you could store a value to a variable before a goto statement and
to return it checks for each value with an if statement and when it finds
the correct value you use a goto statement to go back where you want. 
This will not simplify your program, but make it more complicated, take
up more space, and run slower.  I'd suggest just using external programs.
 I know you said you didn't want to, but I didn't want to before and now
I use it all the time.  BTW, the smaller a program is the faster it runs,
so if you have code that is used over and over it's a lot faster to have
it run an external program.  I've also figured out how to create user
defined functions that can accept 1 parameter and return 1 value. 
Specifically the program I wrote takes an integer as a parameter and
returns the number converted to a string.  I use this in many programs
and it saves space not using it within every program that uses it.


Sincerely,
The Unibomer

Jared Ivey
Unibomer@Juno.com
Ham Call Sign: KF4BXL
The Unibomer's Shack:
     http://www.geocities.com/SiliconValley/Vista/7342/
 _______________________
|  Florida Times Union  |
|=======================|
| Unibomer Strikes Again|
|   ~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~~ |
| ~~~~~~~~~~~~~~~~~~~~• |
|_______________________|


References: