Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIM, TYPE, and STRING Woes
#1
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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
REDIM, TYPE, and STRING Woes - by TerryRitchie - 04-12-2023, 05:57 AM
RE: REDIM, TYPE, and STRING Woes - by mnrvovrfc - 04-12-2023, 10:24 AM
RE: REDIM, TYPE, and STRING Woes - by bplus - 04-12-2023, 03:50 PM
RE: REDIM, TYPE, and STRING Woes - by mnrvovrfc - 04-12-2023, 04:34 PM
RE: REDIM, TYPE, and STRING Woes - by DSMan195276 - 04-12-2023, 04:15 PM
RE: REDIM, TYPE, and STRING Woes - by mnrvovrfc - 04-12-2023, 04:33 PM
RE: REDIM, TYPE, and STRING Woes - by bplus - 04-12-2023, 04:41 PM
RE: REDIM, TYPE, and STRING Woes - by bplus - 04-12-2023, 05:59 PM
RE: REDIM, TYPE, and STRING Woes - by bplus - 04-12-2023, 06:09 PM
RE: REDIM, TYPE, and STRING Woes - by DSMan195276 - 04-12-2023, 10:14 PM
RE: REDIM, TYPE, and STRING Woes - by SMcNeill - 04-12-2023, 10:20 PM
RE: REDIM, TYPE, and STRING Woes - by DSMan195276 - 04-12-2023, 10:33 PM
RE: REDIM, TYPE, and STRING Woes - by Kernelpanic - 04-12-2023, 11:48 PM
RE: REDIM, TYPE, and STRING Woes - by DSMan195276 - 04-13-2023, 05:17 AM



Users browsing this thread: 8 Guest(s)