Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

One stupid question that need to be answer


Jacquelinett
 Share

Recommended Posts

Okay. I know this is stupid, but… do i have to have the "byval" thingy every time i put something in the ()?

Like:

I like to put:
Public Function GetPlayerSomething( Byval Index as long, something as long, someotherthing as Long) as Long

but, after looked at stuffs in Eclipse, i was thinking about:
Public Function GetPlayerSomething( Byval Index as Long, Byval Something as Long, Byval Someotherthing as Long) as long

Do i really have to add the Byval thingy?
Link to comment
Share on other sites

It has to do with the passing of values to the sub routine or function. ByVal is used if you want to make sure that the value stays the same throughout the destination sub/function. It is just an extra thing that is added as far as I can tell as you can still achieve the same result using ByRef or not using either.

If you want examples and such this is a good link:
http://www.techrepublic.com/article/vb6-tip-understanding-the-importance-of-byval-and-byref-keywords/5516744
Link to comment
Share on other sites

It does not matter if Byval is a string, integer, long, byte, boolean, double, ect.

ByVal - you are only passing the value of the argument

ByRef-  you are passing the memory location

~~if its undeclared its ByVal by default, so its not really needed.~~

When it's ByRef when you change it in the sub or function you change the variable in the sub or function that it was called from.

It is NOT recommended that you ever use ByRef in EO.

* * *

ByRef Example

```
Sub DoSomething()

    dim x as long

    x = 5

    call Example (x) 'after call Example the X in this sub should equal 10

end sub

Sub Example (ByRef x as long)

    dim y as long

    y = 5

    x = y + x

End Sub
```

* * *

ByVal Example

```
Sub DoSomething()

    dim x as long

    x = 5

    call Example (x) 'after call Example the X in this sub should still be 5

end sub

Sub Example (ByVal x as long)

    dim y as long

    y = 5

    x = y + x

End Sub
```
These examples are based on memory and might not work as expected
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...