Author Topic: FUNCTION SUB Passing Vars Revisited  (Read 2984 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
FUNCTION SUB Passing Vars Revisited
« 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?
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: FUNCTION SUB Passing Vars Revisited
« Reply #1 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.
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Marked as best answer by xra7en on December 11, 2018, 12:23:46 pm

FellippeHeitor

  • Guest
Re: FUNCTION SUB Passing Vars Revisited
« Reply #2 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.
« Last Edit: December 11, 2018, 02:16:14 pm by FellippeHeitor »

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: FUNCTION SUB Passing Vars Revisited
« Reply #3 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.
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: FUNCTION SUB Passing Vars Revisited
« Reply #4 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/