Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turbo BASIC (DOS)

Status
Not open for further replies.

remwlf

Programmer
Jan 20, 2003
2
US
How do I define a one (1) position string variable in an old DOS version of Turbo Basic? Thanks.
 
Unlike the newer Microsoft BASIC versions, there is no fixed-length string type in TB. You can simulate the effect to a degree by setting the string variable to a value of the length desired...
Code:
  c$ = "z"
...and then use LSET to assign other values to it. (LSET assigns data in-place and does not alter the length of the target string.)

The example program below (which I compiled and tested in Turbo BASIC v1.1)...
Code:
 a$ = "xxx"   ' 3-buyte string
 b$ = "yy"    ' 2-byte string
 c$ = "z"     ' 1-byte string
 LSET a$ = "aa"
 LSET b$ = "bb"
 LSET c$ = "cc"
 PRINT "a = ["; a$; "]"
 PRINT "b = ["; b$; "]"
 PRINT "c = ["; c$; "]"
 end
...produces this output when run...
Code:
 a = [aa ]
 b = [bb]
 c = [c]

The behavior of c$ above is kind of what you asked for. Note that if you mistakenly use...
Code:
  c$ = "cc"
...instead of...
Code:
  LSET c$ = "cc"
...you will alter the length of c$, destroying the effect you wanted.

- Chuck Somerville
 
Oops, almost forgot - There's a Borland BASIC Forum here.

forum201

(This is the BASIC: Microsoft Forum.)

- Chuck Somerville
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top