Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/12/2009, 10:42
Avatar de bigprice
bigprice
 
Fecha de Ingreso: diciembre-2009
Mensajes: 30
Antigüedad: 15 años, 3 meses
Puntos: 0
Información controlar excepcion nullReferenceException

Mi pregunta es como evitar que ocurra la excepcion NullRefernceException ya que me aparece cuando ejecuto un formulario donde doy clic al boton 'Borrar' y me limpia el textbox seleccionado, el error aparece en la linea Me.Controls(Me.cajatexto).Text = "", creo que tengo mal declarada o instanciada la variable cajatexto, alguien podria ayudarme porfavor ya que me pide que use 'new', pero me marca un erro de sobrecarga:

Public Class usuarios
Private cajatexto As String

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Me.Controls(Me.cajatexto).Text = ""
Me.Controls(Me.cajatexto).Focus()
Catch exception As NullReferenceException
MsgBox("Error al borrar", MsgBoxStyle.Critical)
End Try
End sub

Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter
Me.cajatexto = CType(sender, TextBox).Name
End Sub

End class