Pregunta

I am trying to learn Visual Basic and am working through a text book that my son used for a class. Each time I create an event handler by double clicking on the design page, the code that automatically populates is almost identical to the code in the book, except the byval portion is omitted from the code. Can someone explain to me why this happens. I have included an example of the book code and the code I end up with below.

Private Sub frmConversion_Load(sender AS System.Object, e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub frmConversion_Load(ByVal sender AS System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
¿Fue útil?

Solución

Looking at the Form.Load Event in MSDN it shows the event in the style of your second example. It looks like according to this Microsoft.Connect request page the earlier versions of Visual Studio put in the ByVal, but since it is the default it was removed in Visual Studio 2010 SP1. The answer to your question is the example code in the book was created with an older version of Visual Studio.

Otros consejos

I'm guessing the second code snippet is the automated code? You don't really need to mess about with that at all. There may be a chapter on the difference between 'ByVal' and 'ByRef' and it also depends on how old the book is and what version of VS you are using, assuming you are using Visual Studio (VS). If it isn't in the book click here to find out the difference. And the use of ByVal and ByRef is there too. I think. Hope this helped.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top