DAY 031: BYVAL
#1
SYNTAX

For us Rednecks... I like ta BYVAL, Pat. I'd like a P.

For everyone else...

BYVAL

So all this really is is a way to tell the system we will be passing a variable in a library variable list by value rather than by reference. We are basically defining the passing mechanism.

So what's the difference you ask?

In short, passing by value passes the actual value of the variable to the sub-procedure, and back.

Passing by reference means we can mess with the variable name from the call list to the library, sub, or function, and modify the programming element underlying the argument in the calling code. The position in the list is all that matters.

Here is a sub example of passing two variables by reference...

Code: (Select All)
CALL Pete(smart, ascii) ' But not on weekends and not past 5pm M-F.
PRINT smart, ascii

SUB Pete (dumb, ascii)
    dumb = -1
    ascii = 1
END SUB

Output -1, 1

So in this reference example, we see the variable value of dumb got passed by reference to the variable, "smart".

On the other hand, passing by value would mean the value of the variable assigned to the name of the variable would remain the same. So the code would need to be changed from dumb =-1 to smart = -1 to get the same output, but...

Sorry, I can't demo BYVAL in a sub or function, because this keyword is only available for use in  DECLARE LIBRARY statements.

So here is a Windows example to minimize and maximize the window using BYVAL in a DECLARE Library statement...

Code: (Select All)
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION ShowWindow& (BYVAL hwnd AS LONG, BYVAL nCmdShow AS LONG) 'maximize process
END DECLARE

hWnd& = _WINDOWHANDLE

_KEYCLEAR
PRINT "Press a key to minimize this window and then press a key again to restore it..."
SLEEP
y& = ShowWindow&(hWnd&, 2) ' Minimize
_KEYCLEAR
SLEEP
PRINT: PRINT "We're back!"
y& = ShowWindow&(hWnd&, 9) ' Restore

If anyone has any example(s) that work in Linux, or Mac; or any additional info to post, feel free.

Right now, I have to solve the puzzle...

_ _ c k    J _ _    B _ d _ n

Let's Go Brandon!
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
DAY 031: BYVAL - by Pete - 12-12-2022, 02:37 AM
RE: DAY 031: BYVAL - by mnrvovrfc - 12-12-2022, 08:43 AM
RE: DAY 031: BYVAL - by SpriggsySpriggs - 12-14-2022, 05:01 PM
RE: DAY 031: BYVAL - by Pete - 12-14-2022, 07:15 PM
RE: DAY 031: BYVAL - by SMcNeill - 12-14-2022, 07:57 PM
RE: DAY 031: BYVAL - by SpriggsySpriggs - 12-14-2022, 08:06 PM
RE: DAY 031: BYVAL - by Pete - 12-14-2022, 08:10 PM
RE: DAY 031: BYVAL - by mnrvovrfc - 12-14-2022, 09:06 PM
RE: DAY 031: BYVAL - by SpriggsySpriggs - 12-14-2022, 09:18 PM



Users browsing this thread: 3 Guest(s)