看看下面的代码,怎么没有错误提示呀!!!!!!
自己建的类:
Private name As String
Public Property nm() As String
Get
Return Me.name
End Get
Set(ByVal value As String)
Try
If value <= 10 And value > = 1 Then
Me.name = value
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Set
End Property
按钮为4:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim nam As New Class1
nam.nm = 1333
MessageBox.Show(nam.nm)
End Sub
[解决办法]
楼主错误理解了Try的使用方法,如果没有出系统级别错误Try是不会报错的
应将如下代码进行修改:
Try
If value <= 10 And value > = 1 Then
Me.name = value
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
改后代码:
If value <= 10 And value > = 1 Then
Me.name = value
Else
MsgBox(Value)
End If