Why is the reason for this error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

While I was playing with VB.NET windows application I came across one
particular error.
Purposefully I made a button array and try to add an event handler like a
normal button.
Please find the code below.
------------------------------------------------------
Public Sub Start()
Dim But2(2) As Button
But2(1) = New Button
But2(0) = New Button
But2(1).Text = "Age"
But2(0).Text = "Man"

AddHandler But2.Click, AddressOf clickNewbutton
End Sub

Private Sub clickNewbutton(ByVal sender As Object, ByVal evArgs As
EventArgs)
MessageBox.Show("Hello from the new Button" & sender.ToString)
End Su
-----------------------------------------------------------------------------------
During compilation instead of prompting an user error message IDE crashed
with following error

"Visual Basic .Net compiler is unable to recover from the following error:
System Error &Hc0000005& (Visual Basic internal compiler error)
Save your work and restart Visual Studio .Net"

What is the reason for this compiler error?

JACOB P. JOJAN (MCP)
Satyam Computer Services Ltd.
 
You need to assign the click event handler to each button in the array, not
to the array itself:

AddHandler But2(0).Click, AddressOf clickNewButton

Ron
 
Thanks For the link Micheal.
But I am able to add array of controls just the way I mentioned
To make it work I have to change the way in which handler is added (As
mentioned by Ryong).

But my question here is why the compiler crashed instead of throwing syntax
error or compiler error.
 
Jacob said:
But my question here is why the compiler crashed instead of throwing syntax
error or compiler error.

That is a good question! A well written compiler should gracefully
handle the parsing of all tokens and should emit all syntax errors
without choking on the input stream!
 
Back
Top