Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of Functions
#41
@PhilOfPerth +1 thats pretty good! I thought it would be harder. More than one way to skin the ole cat Smile
b = b + ...
Reply
#42
(05-28-2025, 09:17 AM)bplus Wrote: @PhilOfPerth +1 thats pretty good! I thought it would be harder. More than one way to skin the ole cat Smile

Comes from years of practice at dodging the chores!   Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#43
Guys, I don't know why you like to overthink these things.   Let me give you some simple truths about SUBS and FUNCTIONS:

1) SUBS and FUNCTIONS perform in exactly the same way.  Anything you do with one, you can do with the other.  The *ONLY* difference is that a FUNCTION returns a value via the NAME, while a SUB doesn't.  There is absolutely nothing stopping you from swapping between a SUB or FUNCTION interchangably.

The only caveat to that is that FUNCTIONS can be passed as parameters or operators and SUBS can't.  A SUB has to be a stand-alone process and can't be part of the same line segment or passed as a parameter or operator.

X = X + Foo(whatever)   <-- Foo is a Function, it can be used in the formula to the left with no issue.
FUNCTION Foo (whatever)
   Foo = whatever * whatever
END FUNCTION

You can't do something like:

X = X + Foo whatever, return   <-- Trying to call this sub will generate errors and die on you.  
SUB Foo (whatever, return)
   return = whatever * whatever
END SUB

Foo whatever, return: X = X + return  <-- Note that this *WILL* work just fine for you.
SUB Foo (whatever, return)
   return = whatever * whatever
END SUB

There's honestly no real magic difference between one or the other.  The only real difference is that FUNCTIONS return a value from their name, and they can be used as a parameter or operator.  That's it.  Otherwise, the two follow 100% of the same rules and behavior with each other.
Reply
#44
(05-28-2025, 09:53 AM)SMcNeill Wrote: Guys, I don't know why you like to overthink these things.   Let me give you some simple truths about SUBS and FUNCTIONS:

1) SUBS and FUNCTIONS perform in exactly the same way.  Anything you do with one, you can do with the other.  The *ONLY* difference is that a FUNCTION returns a value via the NAME, while a SUB doesn't.  There is absolutely nothing stopping you from swapping between a SUB or FUNCTION interchangably.

The only caveat to that is that FUNCTIONS can be passed as parameters or operators and SUBS can't.  A SUB has to be a stand-alone process and can't be part of the same line segment or passed as a parameter or operator.

X = X + Foo(whatever)   <-- Foo is a Function, it can be used in the formula to the left with no issue.
FUNCTION Foo (whatever)
   Foo = whatever * whatever
END FUNCTION

You can't do something like:

X = X + Foo whatever, return   <-- Trying to call this sub will generate errors and die on you.  
SUB Foo (whatever, return)
   return = whatever * whatever
END SUB

Foo whatever, return: X = X + return  <-- Note that this *WILL* work just fine for you.
SUB Foo (whatever, return)
   return = whatever * whatever
END SUB

There's honestly no real magic difference between one or the other.  The only real difference is that FUNCTIONS return a value from their name, and they can be used as a parameter or operator.  That's it.  Otherwise, the two follow 100% of the same rules and behavior with each other.

Ok, thanks both. I guess I'll stay with the "devil I know" (a bit), then, rather than the devil I barely knew at all until this thread. 
At least, I know what the devil looks like now!
Much appreciated.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#45
To the Most Illustrious Highness Administration, can't you finally do something about the full quotes?

Half a page of full quotes, and then one sentence as a reply!  Angry This is just annoying and disrupts the flow of reading.

[Image: No-Fullquotes.jpg]
Reply
#46
@developers of compiler of QB64pe...
I found confounding the example of PhilofPert at #40 about variable a.
It is a single variable declared at beginning of the code as DIM SHARED so global and visible anywhere...
then it has been passed as parameter to sub ADDRANDOM (a) and this last has in declaration a parameter of kind single with the same name a.
In the Sub AddRandom (a) the variable has been used as counter in a FOR/NEXT loop. So it has been changed taking the values before 1 and then 2 and ending in exiting the FOR loop as value 3. 
The parameter a has not been changed because it has been passed for value to the sub. 
But why the compiler does not change a because it is the global anywhere visible SHARED variable? Is there no conflict using a SHARED variable as parameter passed for value to a procedure? it is already visible in the procedure! Does the compiler always overwrite the condition of SHARED variables if they have been passed as parameters with limitation of the access to their value?
In other words, if we could observe 'a' from inside SUB AddRandom and from main at the first cycle of FOR it should be equal to 1 in both sides, while ending the procedure SUB the compiler restore the entering in sub value of 'a' .
Is it the same in QBasic?
Reply
#47
(05-28-2025, 05:08 PM)Kernelpanic Wrote: To the Most Illustrious Highness Administration, can't you finally do something about the full quotes?

Half a page of full quotes, and then one sentence as a reply!  Angry This is just annoying and disrupts the flow of reading.

[Image: No-Fullquotes.jpg]
No. Big Grin Big Grin Big Grin
Reply
#48
Okay, and without full quoting the above sarcastic reply...

I don't recall any software option to block the display of quoting. Now as programmers anyone with enough experience could make an ap to download the current page, parse out full quoted textareas, and then redisplay that page in their browser.

You know the well spring for this forum, and the QB64 forums preceding it, didn't have this problem. It was threaded in such a way that you replied specifically to the post in question. The thread and posts were all in hyperlinks in a tree-like formation. Very dull, but it was a neat system for not having to worry about including the post in question in your reply. Ah, the good ol' days. You know water even tasted different back then, coming from aqueducts and all. So unless you want to return to the past, and join the QBasic Forum, I suggest you get the lead out, and try my ap suggestion. It might even be a fun code!

Pete Wink
Reply
#49
(05-29-2025, 12:22 AM)Pete Wrote: You know the well spring for this forum, and the QB64 forums preceding it, didn't have this problem. It was threaded in such a way that you replied specifically to the post in question. The thread and posts were all in hyperlinks in a tree-like formation. Very dull, but it was a neat system for not having to worry about including the post in question in your reply. Ah, the good ol' days. You know water even tasted different back then, coming from aqueducts and all. So unless you want to return to the past, and join the QBasic Forum, I suggest you get the lead out, and try my ap suggestion. It might even be a fun code!

Pete Wink

Isn't this post reduced? I just included the section I wanted to re-quote
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#50
(05-29-2025, 12:22 AM)Pete Wrote: You know the well spring for this forum, and the QB64 forums preceding it, didn't have this problem. It was threaded in such a way that you replied specifically to the post in question. The thread and posts were all in hyperlinks in a tree-like formation. Very dull, but it was a neat system for not having to worry about including the post in question in your reply. 

You know, there's an option in the control panel or somewhere that allows you to toggle to threaded mode for viewing posts.  At least, I think there is...

[Image: image.png]

Click to expand and you'll see the options above, on the right hand side of the image.  It's in the user control panel, EDIT OPTIONS.
Reply




Users browsing this thread: 8 Guest(s)