Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't pass a fixed string array to a sub..
#1
Can't compile this program
It gives an Illegal specification at parameter b in line 2
Code:
#define s7 as string*7
declare sub subru (b() as s7)
dim as s7 a(1)
a(1)="10000  "
subru a()
sleep

sub subru (b() as s7)
print b(1)
end sub

If I declare b() as ant, it gives me a Type mismatch in parameter 1 at the
line where the call is
Antoni
Reply
#2
The #define command is a preprossesor thing. That means that whatever is inside the #define will be replaced where its put. Right now, s7 is "as string*7", so with the sub, its declared like this:
Code:
sub subru (b() as as string*7)
Plus you can't multiply strings by a number. Actually, you cant multiply strings at all.
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Reply
#3
umm yes you can :wink: that's how to make string fixed-length.
such as:
dim a as string*7
a="12345678"
print a
sleep

it means that the string can only hold 7 chars.
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Reply
#4
I didn't know QB allowed that, another quirk.. you can't do "foo as string * 123" with byref args but it's allowed by descriptor.. Sorry, but i can't add that, it would need too many hacks, and it's the first time i see that being used.

The way around is declaring it as a single field type and passing the UDT array instead by descriptor.
Reply
#5
How does BYREF work? I have look at the FB Keywords Reference, but it says the same as BSAVE..
Reply
#6
v!ctor: I never said QB could do that. Just tried it in FB...
Antoni
Reply
#7
But strange enough (at least for me), QB allows that with arrays passed by descriptor..

BYREF is used to declare the mode of function arguments, it's the default one. It means the address of the argument will be passed, not the argument itself, BYVAL should be always used when you don't want explicitly to change the argument inside the function called.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)