QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: xra7en on December 11, 2018, 02:09:59 pm

Title: FUNCTION SUB Passing Vars Revisited
Post by: xra7en on December 11, 2018, 02:09:59 pm
I think it is just me, but I'll ask anyways. I think I am doing something wrong
Code: QB64: [Select]
  1. sub cool_sub(a as string, i as integer)
  2. '// hottest qb64 app on record :-)
  3. end sub '/// this does not error
  4.  
  5. cool_sub(this_str, and_this_integer) '// THIS ERRORS AS A SYNTAX WHY?

I could be wrong, but I thought you can send various vars to a sub or function. I know you cannot do UDT.

What is wrong with this picture?
Title: Re: FUNCTION SUB Passing Vars Revisited
Post by: xra7en on December 11, 2018, 02:13:21 pm
never mind - just figured it out
have to use a "call"

Code: QB64: [Select]
  1. call cool_sub(this_str, and_this_integer)

caught it right after I posted it, but decided to leave it for anyone else that gets a similar issue.
Title: Re: FUNCTION SUB Passing Vars Revisited
Post by: FellippeHeitor on December 11, 2018, 02:14:34 pm
Use CALL or drop it altogether, but if you don't use CALL, then you don't use parentheses either.

Code: QB64: [Select]
  1. cool_sub this_str, and_this_integer

And SUB parameters can be UDTs. Arrays too. And arrays of UDTs too.
Title: Re: FUNCTION SUB Passing Vars Revisited
Post by: xra7en on December 11, 2018, 02:23:33 pm
Use CALL or drop it altogether, but if you don't use CALL, then you don't use parentheses either.

Code: QB64: [Select]
  1. cool_sub this_str, and_this_integer

And SUB parameters can be UDTs. Arrays too. And arrays of UDTs too.

Thanks for that tip!
That was one thing that got me confused when returning to QB, QB64 ha some nice quirks and other functions I need to explore. I like this answer better.
Title: Re: FUNCTION SUB Passing Vars Revisited
Post by: Pete on December 12, 2018, 01:08:21 pm
One reason I prefer the CALL method. I program in Notepad a lot, and If I wanted to find my sub calls, I just did a universal search for "CALL" .

Pete