Hi,
according to the help,
QuoteA simpler method to access a pointer to an array of data is to use the standard array indexes. In this manner you do not have to account for the size of the variable, as the type cast will specify the size of the data being stored.
I'm trying to play with a dynamic string array with wrong results
string temp
int totmsg,nmsg
totmsg = 10
pointer pDimMsg = new(string,totmsg)
for nmsg = 1 to totmsg
temp = string$(5,chr$(64+nmsg))
#<string>pDimMsg[nmsg-1] = temp
print temp," ---> ",#<string>pDimMsg[nmsg-1]
next nmsg
delete pDimMsg
do:until inkey$ <> ""
end
Can someone say me where I'm wrong?
Thanks!
Sergio
Probably not the best way but this is one way to get the correct results.
string temp
int totmsg,nmsg
totmsg = 10
pointer porig
pointer pDimMsg = new(string,totmsg)
porig=pDimMsg
for nmsg = 1 to totmsg-1
temp = string$(5,chr$(64+nmsg))
#<string>pDimMsg = temp
print temp," ---> ",#<string>pDimMsg
pDimMsg+=255
next nmsg
delete porig
do:until inkey$ <> ""
end
Larry
A string array has two dimensions. The implicit one is 255 characters, so you have to specify both indexes. In this case you want the first character location (0) of each string (0-9)
string temp
int totmsg,nmsg
totmsg = 10
pointer pDimMsg = new(string,totmsg)
for nmsg = 0 to totmsg-1
temp = string$(5,chr$(64+nmsg+1))
#<string>pDimMsg[0,nmsg] = temp
print temp," ---> ",#<string>pDimMsg[0,nmsg]
next nmsg
delete pDimMsg
do:until inkey$ <> ""
end
Think of it this way. You know a string is 255 CHARacters. So if you wanted to allocate the same memory using a CHAR it would look like this:
pointer pDimMsg = new(CHAR,255 * totmsg)
Which is a dimension of [255,10]
Paul.
Thanks! :)
Sergio