04-12-2023, 05:57 AM
(This post was last modified: 04-12-2023, 06:47 AM by TerryRitchie.)
Ok, been pulling my hair out for last 4 hours until I realized what was going on.
I have a TYPE with 3 integers and a string:
TYPE MYTYPE
INT1 AS INTEGER
INT2 AS INTEGER
INT3 AS INTEGER
INFO AS STRING
END TYPE
Then used it as so:
REDIM MYVARIABLE(1) AS MYTYPE
So far so good. As I start putting data into the array I need to resize it from time to time:
REDIM _PRESERVE MYVARIABLE(UBOUND(MYVARIABLE) + 1) AS MYTYPE
Still good right? Nope. The previous data gets completely garbled. The problem you ask?
INFO AS STRING
Change it to:
INFO AS STRING * 20
and all is good in QB64 land.
It seems variable length strings are a no-no when using REDIM _PRESERVE
If this is already a known issue then somehow I have missed it all these years. If it isn't then this is a warning letting others know this happens.
I was ready to throw my joystick through my screen until it finally dawned on me as to what may have been happening. The integers I was storing ranged from 1 to 6 but somehow they were changing to 16, 57, 3471, etc.. I thought maybe I was going nuts for a while, LOL.
Ugh.
I have a TYPE with 3 integers and a string:
TYPE MYTYPE
INT1 AS INTEGER
INT2 AS INTEGER
INT3 AS INTEGER
INFO AS STRING
END TYPE
Then used it as so:
REDIM MYVARIABLE(1) AS MYTYPE
So far so good. As I start putting data into the array I need to resize it from time to time:
REDIM _PRESERVE MYVARIABLE(UBOUND(MYVARIABLE) + 1) AS MYTYPE
Still good right? Nope. The previous data gets completely garbled. The problem you ask?
INFO AS STRING
Change it to:
INFO AS STRING * 20
and all is good in QB64 land.
It seems variable length strings are a no-no when using REDIM _PRESERVE
If this is already a known issue then somehow I have missed it all these years. If it isn't then this is a warning letting others know this happens.
I was ready to throw my joystick through my screen until it finally dawned on me as to what may have been happening. The integers I was storing ranged from 1 to 6 but somehow they were changing to 16, 57, 3471, etc.. I thought maybe I was going nuts for a while, LOL.
Ugh.