Page 1 of 1

POKE AGAIN!!

Posted: Fri Apr 01, 2005 5:52 am
by LILY
Can somebody explain that to mer:

Let's have A$(1,1)="A"
Following the hereunder code I can print AD(1,1), AD(1,1)+1, AD(1,1)+2
line 140
The repective values are "1", " 137" and "18"
But if I want to get thes values in Z1 and Z2 (line 150) I get "0" and"0"
Why? Z1 was primitively 1 for instance and Z2 should be 256X137?



120 DEF SEG


130 AD(1,1)=VARPTR(A$(1,1))
140 PRINT PEEK(AD(1,1)),PEEK(AD(1,1)+1),PEEK(AD(1,1)+2)
150 Z1=PEEK(AD(1,1)+2):PRINT Z1:Z2=256*PEEK(AD(1,1)+1):PRINT Z2


I am completly lost and understand less and less!!!!
You can run this in QB7.1 to see.

Posted: Sun Jul 03, 2005 3:27 pm
by {Nathan}
Please, you have heard it before. Code tags.

Posted: Tue Jul 05, 2005 5:59 am
by Antoni
Well, you did not posted the complete source so let me guess..

If what you wanted is to have an array n x n of chars you should do

Code: Select all

DIM a$(n,n) as string*1
In that case the array contains the actual characters and your code should work.

If you do

Code: Select all

DIM A$(n,n)
you get an array of variable length string descriptors, the actual strings are stored elsewhere.. so making VARPTR$(A$(1,1)) you get the address of the descriptor, not the strings: You should use SADD to get the actual string.

Notice too that Peek(AD(1,1)+1) will give you the second char of the string at A$(1,1), if it exists,I suppose that's what you want. The string at A$(2,1).

If you run PDS, you should DEF SEG=STR SEG or something like that before peeking strings, as these are not always at the default segment in PDS.

As strings are dynamically assigned and moved around constantly, yout saved addresses will become wrong each time you change a string. You should use SADD before each set of instructions PEEKing strings, it's safer.