string in memory

Página 1/2
| 2

Por TheKid

Paragon (1238)

imagem 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?

Entrar ou registrar-se para comentar

Por meits

Scribe (6533)

imagem de meits

18-02-2021, 23:22

poke the chr$(x) ?

Por TheKid

Paragon (1238)

imagem de TheKid

19-02-2021, 00:06

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

Por meits

Scribe (6533)

imagem de meits

19-02-2021, 00:09

The x is a pokable number. Smile

Por TheKid

Paragon (1238)

imagem 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.

Por ro

Scribe (4913)

imagem 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.

Por theNestruo

Champion (413)

imagem 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

Por TheKid

Paragon (1238)

imagem 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”

Por thegeps

Paragon (1175)

imagem 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

Por Thom

Paladin (703)

imagem 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.

Por ray2day

Paladin (729)

imagem 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...)

Página 1/2
| 2