Re: TIB: String Arrays, GOSUB
[Prev][Next][Index][Thread]
Re: TIB: String Arrays, GOSUB
If you think about it, strings are really just arrays of characters. For
instance, If you look at them like lists, you can represent them
numerically as a position in a predefined character set string. Like....
---------------------------------------------------
" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy1234567890"->abet
{5,40}->dim strarray
For(z,1,5)
InpStr "enter a string:",S
Disp "Encoding..."
If lngth S>40
sub(S,1,40)->S
For(x,1,40-lngth S)
S+" "->S
For(Y,1,40)
For(x,1,lngth abet)
If sub(abet,x,1)=sub(S,Y,1)
strarray(z,Y)=x
End
End
End
---------------------------------------------------
This prompts for 5 strings, encodes them into the matrix strarray, and
quits. This does take a bit, though, and the strings are a fixed length
(40 in this example, but can be shrunk or expanded as needed). The
encoding does take a bit, though. Now, to extract this info...
---------------------------------------------------
For(z,1,5)
" "->S
For(x,1,40)
S+sub(abet,strarray(z,x))->S
End
sub(S,2,40)->S
Disp S
End
---------------------------------------------------
This decoding takes each string out of strarray, assembles it into the
string S, and displays it. Again, it assumes
+---------------------------------------------+
|There's too much blood in my caffeine system.|
| http://barry11.home.ml.org |
+---------------------------------------------+
On Tue, 21 Oct 1997 15:44:04 -0700 Peter Sahlstrom
<petes@technologist.com> writes:
>This is a multi-part message in MIME format.
>--------------6AD6F5043AE75C9573169BD4
>Content-Type: multipart/alternative;
>boundary="------------395B062970B41D6C72465657"
>
>
>--------------395B062970B41D6C72465657
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
>I originally learned basic using GW-BASIC in about 1988, and I've
>noticed two major things TI-BASIC appears to be missing:
>
> * String Arrays-for instance, A$(1)="A", A$(2)="B", A$(3)="C", etc.
> Is there a way to simulate these in TI-BASIC?
> * GOSUB & Subroutines-for instance:
> 10 PRINT "Hello";
> 20 GOSUB 50
> 30 PRINT "Goodbye";
> 40 GOSUB 50:END
> 50 FOR I=1 TO 5
> 60 PRINT ".";
> 70 FOR J=1 TO 1000
> 80 NEXT J
> 90 NEXT I
> 100 RETURN
>
> 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.
>
>Thanks for your help everybody!
>
>--
>Peter Sahlstrom
>petes@technologist.com/petersahlstrom@geocities.com
>http://www.geocities.com/SiliconValley/Lakes/1950 (Homepage)
>
>
>--------------395B062970B41D6C72465657
>Content-Type: text/html; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
><HTML>
>I originally learned basic using GW-BASIC in about 1988, and I've
>noticed
>two major things TI-BASIC appears to be missing:
><UL>
><LI>
><FONT COLOR="#FF6666">String Arrays</FONT>-for instance, A$(1)="A",
>A$(2)="B",
>A$(3)="C", etc. Is there a way to simulate these in
>TI-BASIC?</LI>
>
><LI>
><FONT COLOR="#FF6666">GOSUB & Subroutines</FONT>-for
>instance:</LI>
>
><UL>10 PRINT "Hello";
><BR>20 <FONT COLOR="#FF6666">GOSUB 50</FONT>
><BR>30 PRINT "Goodbye";
><BR>40 <FONT COLOR="#FF6666">GOSUB 50</FONT>:END
><BR>50 FOR I=1 TO 5
><BR>60 PRINT ".";
><BR>70 FOR J=1 TO 1000
><BR>80 NEXT J
><BR>90 NEXT I
><BR>100 RETURN</UL>
>
>
><P>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.</UL>
>Thanks for your help everybody!
>
><P>--
><BR>Peter Sahlstrom
><BR>petes@technologist.com/petersahlstrom@geocities.com
><BR><A
>HREF="http://www.geocities.com/SiliconValley/Lakes/1950">http://www.geocities.com/SiliconValley/Lakes/1950</A>
>(Homepage)
><BR> </HTML>
>
>--------------395B062970B41D6C72465657--
>
>--------------6AD6F5043AE75C9573169BD4
>Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
>Content-Transfer-Encoding: 7bit
>Content-Description: Card for Peter Sahlstrom
>Content-Disposition: attachment; filename="vcard.vcf"
>
>begin: vcard
>fn: Peter Sahlstrom
>n: Sahlstrom;Peter
>email;internet: petes@technologist.com
>x-mozilla-cpt: ;0
>x-mozilla-html: FALSE
>version: 2.1
>end: vcard
>
>
>--------------6AD6F5043AE75C9573169BD4--
>
>
References: