06-09-2024, 08:02 PM
(06-09-2024, 05:33 PM)TerryRitchie Wrote: I just ran across something that is confusing me.
The User32 function SetCursorPos as outlined here in the Microsoft docs:
https://learn.microsoft.com/en-us/window...tcursorpos
is a function. However, it's being declared as a SUB in the Wiki example code here:
https://qb64phoenix.com/qb64wiki/index.p...Mouse_Area
At first I though this was a typo but the code works. Is this a typo that somehow works? Or is it possible to declare FUNCTIONs as SUBs in certain circumstances?
In the world o' BASIC, we have functions and subroutines. Functions for when we want a value returned, subroutine when we don't want a value returned (I.e. we just want to call the subroutine.)
In the Windows API, we have functions but we do not have subroutines.
When you don't care about the return value for any Windows API function, go ahead and declare it (and use it) as a SUB. (If the return value is a boolean, as in for SUCCESS or FAILURE, you decide whether or not you want to check that for error handling; if so, then declare as a function; if not, then SUB is fine.)
When you do care about the return value for any Windows API function, go ahead and declare it (and use it) as a FUNCTION.
Aside: I'm a Gupta Team Developer programmer by trade. It has functions but does not have subroutines. Every function can be used in an expression when we expect a value returned from it. Every function can also be directly called (like a BASIC subroutine), and the return value is ignored. (Functions can be defined as either returning a value or not returning any value.)