Home | Reviews | GUIpedia | Forum | Fun500
Brandon | QB45 String LengthWhen 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-15 | 9:40 AM |
Todd | Re:QB45 String LengthIn 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-15 | 11:02 AM |
Brandon | Re:QB45 String LengthBut if I use 512, won't that take a lot of ram? | 2009-03-15 | 11:47 AM |
Todd | Re:QB45 String LengthIt 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-15 | 11:55 AM |
Brandon | Re:QB45 String LengthSo there is no dynamic function? | 2009-03-15 | 12:01 PM |
Todd | Re:QB45 String LengthIn QB, I don't think so. I think there might be something in QBX that'll support dynamic strings. | 2009-03-15 | 12:35 PM |
pharoah | Re:QB45 String LengthIt 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-15 | 1:52 PM |
Primis | Re:QB45 String LengthNo, 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-23 | 1:55 AM |
Brandon | Re:QB45 String LengthThe 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-23 | 7:37 AM |
BASIC Programming Help
2021 Brandon Cornell