Jacquelinett Posted October 22, 2011 Author Share Posted October 22, 2011 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 Longbut, 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 longDo i really have to add the Byval thingy? Link to comment Share on other sites More sharing options...
iSKweek Posted October 22, 2011 Share Posted October 22, 2011 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 More sharing options...
Richy420Rich Posted October 22, 2011 Share Posted October 22, 2011 But what of - Byval Msg As String? Surely Strings aren't value, or are they? *_* Link to comment Share on other sites More sharing options...
RyokuHasu Posted October 22, 2011 Share Posted October 22, 2011 It does not matter if Byval is a string, integer, long, byte, boolean, double, ect.ByVal - you are only passing the value of the argumentByRef- 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 10end subSub 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 5end subSub 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 More sharing options...
iSKweek Posted October 22, 2011 Share Posted October 22, 2011 ByRef is the default ;)But yes, your examples are spot on. Link to comment Share on other sites More sharing options...
Richy420Rich Posted October 22, 2011 Share Posted October 22, 2011 Ah that's cool, never knew that. Thanks :) Link to comment Share on other sites More sharing options...
RyokuHasu Posted October 22, 2011 Share Posted October 22, 2011 @Skweek:> ByRef is the default ;)> But yes, your examples are spot on.Woops… lolFOR THE LOVE OF GOD PUT DOWN "ByVal"!!! Link to comment Share on other sites More sharing options...
Robin Posted October 23, 2011 Share Posted October 23, 2011 The reason I make sure to put down ByVal is because ByRef is default. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now