QBasic pass type as function argument -
went old qbasic nostalgic reasons , have never used types , functions in qbasic before young time.
type vector2 x single y single end type function vector2mag (a vector2) vector2mag = sqr((a.x * a.x) + (a.y * a.y)) end function function vector2add (a vector2, b vector2) dim r vector2 r.x = a.x + b.x r.y = a.y + b.y vector2add = r end function
but get
illegal sub/function parameter on current line
using qb64 in both first function lines. google didn't looks doing right. checked passing multiple variables, specifying type parameter, how use types nothing helped.
thanks guys.
it has been while, believe problem can't return udt (user defined type, a.k.a. "any type not built in"). need pass third argument vector2add
, make sub
. example:
sub vector2add (r vector2, vector2, b vector2) r.x = a.x + b.x r.y = a.y + b.y end sub
the sub
exact translation equivalent c code, aside syntax differences. reasoning add type suffix name of function
in qb or use default type, may have been overridden defxxx m-n
(or _define
in qb64; , no can't use _define
udts). example, returning string:
'default type identifiers beginning 's' string. ' type suffixes, "as xxxx" clauses , future "defxxx" items override behavior. defstr s-s function swapfirstlast$ (s) swapfirstlast$ = right$(s, 1) + mid$(s, 2, len(s) - 2) + left$(s, 1) end function
qb64 kinda limited in regard since aims compatible syntax used quickbasic 4.5 possible. freebasic, language based on qb, has no such restriction:
'notice "as vector2" @ end of next line , return statement ' fb introduced functions (originally used return ' "old-style" subroutine invoked via gosub statement). function vector2add (a vector2, b vector2) vector2 dim r vector2 r.x = a.x + b.x r.y = a.y + b.y return r end function
the important point remember qb64 still qb, except compile code run on modern operating systems (rather dos). freebasic, on other hand, chose sacrifice compatibility in favor of creating more "modern" language retains qb's syntax.
Comments
Post a Comment