string in memory

Page 1/2
| 2

Par TheKid

Paragon (1238)

Portrait de TheKid

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 ou Inscrivez-vous pour poster

Par meits

Scribe (6571)

Portrait de meits

18-02-2021, 23:22

poke the chr$(x) ?

Par TheKid

Paragon (1238)

Portrait de TheKid

19-02-2021, 00:06

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

Par meits

Scribe (6571)

Portrait de meits

19-02-2021, 00:09

The x is a pokable number. Smile

Par TheKid

Paragon (1238)

Portrait de TheKid

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.

Par ro

Scribe (5056)

Portrait de ro

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.

Par theNestruo

Champion (428)

Portrait de theNestruo

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

Par TheKid

Paragon (1238)

Portrait de TheKid

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”

Par thegeps

Paragon (1249)

Portrait de thegeps

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

Par Thom

Paladin (709)

Portrait de Thom

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.

Par ray2day

Paladin (752)

Portrait de ray2day

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