string in memory

Page 1/2
| 2

By TheKid

Paragon (1080)

TheKid's picture

18-02-2021, 23:11

Hi, I have a simple question (I guess).

I am programming in MSX-basic and I have a string variable TX$="example".
I want to 'give' this variable from one listing to another. With numbers I can use poke, and use peek in the next listing to read the variable, but how can I acchieve this for a string variable?

Login or register to post comments

By Meits

Scribe (6200)

Meits's picture

18-02-2021, 23:22

poke the chr$(x) ?

By TheKid

Paragon (1080)

TheKid's picture

19-02-2021, 00:06

yeah, but how? Or another way to get a string accross listings

By Meits

Scribe (6200)

Meits's picture

19-02-2021, 00:09

The x is a pokable number. Smile

By TheKid

Paragon (1080)

TheKid's picture

19-02-2021, 07:53

Okay, I hoped for a better way, but converting each string to character value and place them in a poke is doable, thanx.

By ro

Scribe (4324)

ro's picture

19-02-2021, 08:22

Funny, I did exactly that last evening. Trying to figure out how to put a string in memory in basic. Havent dun baisc for 30 years...
I could post the solution her if ye like.

By theNestruo

Champion (268)

theNestruo's picture

19-02-2021, 08:28

I'm not quite sure I've understood what are you trying to achieve... but VARPTR() may come handy:

10 DEFINTA-Y:DEFSTRZ:Z="HELLO, MSX!"
20 I=VARPTR(Z):NB=LEN(Z):NP=PEEK(I):?"Length:";NB;NP
30 ZA=RIGHT$("00"+HEX$(PEEK(I+2)),2)+RIGHT$("00"+HEX$(PEEK(I+1)),2):A=VAL("&H"+ZA):?"Address: &H";ZA;" ";A
40 B=A:E=B+NB-1:FORI=BTOE:C=PEEK(I):?"Char at &H";HEX$(I);": ";CHR$(C);C:NEXT

See it live: https://msxpen.com/codes/-MTtA_WMng0wnKfTYQQf

By TheKid

Paragon (1080)

TheKid's picture

19-02-2021, 09:20

What I want is simple.

In listing A i have a string tx$=“test”

In listing B i want to use tx$ With it’s value “test”

By thegeps

Paladin (670)

thegeps's picture

19-02-2021, 11:20

Not sure, but if you load a new listing probably variables (and varptr too) will be erased. So you have first to peek into varptr pos (offsetting until end of string) and poke values in a safe area (set it using CLEAR). Then load new listing and read (peek) from safe area. Not tested but it should work

By Thom

Hero (658)

Thom's picture

19-02-2021, 15:53

Don't know if it fits into your code, but using sprite$(0)="test" and then in listing B tx$=sprite$(0) could work. The length of the string is limited though.

By ray2day

Hero (617)

ray2day's picture

19-02-2021, 16:26

Quote:

Not sure, but if you load a new listing probably variables (and varptr too) will be erased. So you have first to peek into varptr pos (offsetting until end of string) and poke values in a safe area (set it using CLEAR). Then load new listing and read (peek) from safe area. Not tested but it should work

I think this should be the right way to do it, Remy!
But what part of the memory will be the 'safe area'? (asking myself...)

Page 1/2
| 2