Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable as a reference or value to a function
#9
(07-17-2022, 08:23 PM)Kernelpanic Wrote:
(07-17-2022, 07:41 PM)bplus Wrote: If you want to pass by value, just use a different type than defined in sub or function.
And then why does it work with the "Sub"?

It's exactly like bplus said. In the Sub you wrote this line:

Code: (Select All)
  eingabe = eingabe + 3

But in the Function you wrote this line:

Code: (Select All)
  AlsWert = eingabe + 3

The two pieces of code do fundamentally different things, because only the Sub actually assigns a new value to `eingabe`, the Function version leaves it alone. If you use the same line from the Sub in your Function then it should work as expected. Try changing it to this:

Code: (Select All)
  eingabe = eingabe + 3
  AlsWert = eingabe

It returns the exact same value as before, but also modifies `eingabe` to be the new value.
Reply


Messages In This Thread
RE: Variable as a reference or value to a function - by DSMan195276 - 07-18-2022, 12:57 AM



Users browsing this thread: 6 Guest(s)