Home | Reviews | GUIpedia | Forum | Fun500


BrandonQB45 String Length
When I set up a type, in FB I can do [code]COWS AS STRING[/code] and the string length is dymanic. When I try in QB45, it wants a length, for example [code]COWS AS STRING * 20[/code] Can I have it dynamic length in QB?
2009-03-159:40 AM

ToddRe:QB45 String Length
In most languages, strings can go up to 1024 so if that doesn't work, try other lengths: 512, 256, etc. Then just use something to either store the string length as an integer (not of COWS of course but the buffer used for moving data into COWS). Or you could trim the string when you use it.
2009-03-1511:02 AM

BrandonRe:QB45 String Length
But if I use 512, won't that take a lot of ram?
2009-03-1511:47 AM

ToddRe:QB45 String Length
It could but I think the common is 255. It all depends on what you plan to store in there. If it's something like a widget/control label, I would just try 32 or 48.
2009-03-1511:55 AM

BrandonRe:QB45 String Length
So there is no dynamic function?
2009-03-1512:01 PM

ToddRe:QB45 String Length
In QB, I don't think so. I think there might be something in QBX that'll support dynamic strings.
2009-03-1512:35 PM

pharoahRe:QB45 String Length
It can be dynamic, as long as you are not putting it in a user defined type. Strings in UDTs can't be dynamic. In Freebasic they can because it just puts in a pointer to the string's real location, but in QB/QuickB the string is stored as a number of bytes right with the rest of the UDT.
2009-03-151:52 PM

PrimisRe:QB45 String Length
No, Sorry, but you can cheat like me! *WARNING ENTERING HACKER ZONE* Set a varible for example, [code] DIM SHARED Cows AS String * 25 Cows = "Moo! I'm A Cow!" Moo$ = RTRIM$(Cows) Print "Bucky says: " + Moo$ + " And Proud." Primt "Bucky says: " + Cows + " And Proud." [/code] Will give you the output:" Bucky says: Moo!_I'm_A_Cow!_And_Proud. Bucky says: Moo!_I'm_A_Cow!__________And_Proud." So if you want to, you could RTRIM$ the string and trim off the excess spaces per sub. If I'm not clear let me know.
2009-05-231:55 AM

BrandonRe:QB45 String Length
The problem was that I didn't want to waste RAM by having large Arrays DIMed when all I use is a few characters.
2009-05-237:37 AM

BASIC Programming Help


2021 Brandon Cornell