• Print

Author Topic: subs  (Read 115 times)

23452

  • Jr. Member
  • **
  • Posts: 72
    • Email
subs
« on: November 01, 2012, 06:11:20 PM »
I have a few questions

Is it possible to make a sub run another sub?

Is it possible to print form a sub with out saving the a variable as a string?

Is there a important difference between subs and functions?

mcalkins

  • Hero Member
  • *****
  • Posts: 1269
    • qbasicmichael.com
    • Email
Re: subs
« Reply #1 on: November 01, 2012, 07:06:42 PM »
Quote from: 23452 on November 01, 2012, 06:11:20 PM
Is it possible to make a sub run another sub?

Yes.

Code: [Select]
a
END

SUB a
b
END SUB

SUB b
PRINT "Hello."
END SUB

Quote
Is it possible to print form a sub with out saving the a variable as a string?

What do you mean?

Code: [Select]
DIM i AS LONG
i = 5
PRINT i

Quote
Is there a important difference between subs and functions?

The only difference between a SUB and a FUNCTION is that FUNCTIONs return a value, but SUBs don't.

Code: [Select]
s
PRINT f
END

SUB s
PRINT "in s"
END SUB

FUNCTION f&
PRINT "in f"
f = -3
END FUNCTION

Regards,
Michael
The QBASIC Forum Community: http://www.network54.com/index/10167 Includes off-topic subforums.
QB64 Off-topic subforum: http://qb64offtopic.freeforums.org/

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: subs
« Reply #2 on: November 01, 2012, 07:16:06 PM »
Functions normally only return one value in their name, but you can cheat by sending values through the parameters.

Also you can use a SHARED value to pass values to the main module.

Functions are referenced, not called, so they must be in a statement that returns the value. Parenthesis must be around all parameters.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

23452

  • Jr. Member
  • **
  • Posts: 72
    • Email
Re: subs
« Reply #3 on: November 01, 2012, 07:17:21 PM »
 :-[ I feel stupid now. I was forgetting to call the sub.

Clippy

  • Hero Member
  • *****
  • Posts: 16431
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: subs
« Reply #4 on: November 01, 2012, 10:20:39 PM »
You don't have to use CALL to run a SUB. If you do use parenthesis around the parameters in the call statement.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

  • Print