Qbasicnews.com

Full Version: Passing constant length strings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[syntax="quickbasic"]
dim S as string * 10

sub Foo (byref Text as string * 10)
print Text
end sub

Foo S
[/syntax]

This gives me an illegal specification at parameter 1 in Foo.

I really need to pass a constant length string by reference, because I'm building a generic menu system which shows the contents of a variable by calling a sub to format it right (ie. ShowInteger would format and print an integer, ShowTime would format and show a time value). So I use function pointers where one of the arguments is "byref Var as any" and then in for example ShowInteger I do "byref Var as integer", but if I do "byref Var as string * 30", it complains and gives me the same error.

Anyways, is it possible to pass string * n to a sub at all?
Nope, neither it was in QB, but can't it be just byval as string? Strings passed byval are just pointers to zstring's, the only difference it that the assignaments won't be safe as for fixed-len's or zstring's with known sizes at compile-time.
I can't start using byval, because then the whole generic menu framework that I'm building will be impossible. I need byref as any or "any ptr".

But if there isn't a way to do this, I'll just use variable length strings and remember to clean them up after use (setting all of the string members in the type to "")