初学VB,想自制一个计算器。单位换算。
起初想法是用文本框输入,标签文本作为输出。实时监测文本框输入并实时输出结果。但是运行时,标签一直为空。尝试注释掉text_change()下面的执行代码,随便写点测试代码,发现sub text_change()似乎在文本改变的时候根本没有执行。
请大虾们花分分钟帮看看,问题出在哪儿?
Public Class Frmmain
Dim linput As Single
Dim length As Single
Private Sub Frmmain_Load(sender As Object, e As EventArgs) Handles Me.Load
cbolorg.SelectedIndex = 0
cbolrlt.SelectedIndex = 2
End Sub
Private Sub Textl1_Change()
If IsNumeric(Me.Textl1.Text) = False Then
lblen.Text = "Err"
Exit Sub
End If
Select Case cbolorg.SelectedIndex
Case 0
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Textl1.Text
Case 1
lblen.Text = Val(Textl1.Text) / 12
Case 2
lblen.Text = Val(Textl1.Text) / 25.4
Case 3
lblen.Text = Val(Textl1.Text) / 25400
End Select
Case 1
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text) * 12
Case 1
lblen.Text = Textl1.Text
Case 2
lblen.Text = Val(Textl1.Text) * 304.8
Case 3
lblen.Text = Val(Textl1.Text) * 0.3048
End Select
Case 2
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text) / 12
Case 1
lblen.Text = Val(Textl1.Text) / 304.8
Case 2
lblen.Text = Textl1.Text
Case 3
lblen.Text = Val(Textl1.Text) / 1000
End Select
Case 3
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text * 1000) / 308.4
Case 1
lblen.Text = Val(Textl1.Text * 1000) / 25.4
Case 2
lblen.Text = Val(Textl1.Text) * 1000
Case 3
lblen.Text = Textl1.Text
End Select
End Select
End Sub
End Class
起初想法是用文本框输入,标签文本作为输出。实时监测文本框输入并实时输出结果。但是运行时,标签一直为空。尝试注释掉text_change()下面的执行代码,随便写点测试代码,发现sub text_change()似乎在文本改变的时候根本没有执行。
请大虾们花分分钟帮看看,问题出在哪儿?
Public Class Frmmain
Dim linput As Single
Dim length As Single
Private Sub Frmmain_Load(sender As Object, e As EventArgs) Handles Me.Load
cbolorg.SelectedIndex = 0
cbolrlt.SelectedIndex = 2
End Sub
Private Sub Textl1_Change()
If IsNumeric(Me.Textl1.Text) = False Then
lblen.Text = "Err"
Exit Sub
End If
Select Case cbolorg.SelectedIndex
Case 0
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Textl1.Text
Case 1
lblen.Text = Val(Textl1.Text) / 12
Case 2
lblen.Text = Val(Textl1.Text) / 25.4
Case 3
lblen.Text = Val(Textl1.Text) / 25400
End Select
Case 1
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text) * 12
Case 1
lblen.Text = Textl1.Text
Case 2
lblen.Text = Val(Textl1.Text) * 304.8
Case 3
lblen.Text = Val(Textl1.Text) * 0.3048
End Select
Case 2
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text) / 12
Case 1
lblen.Text = Val(Textl1.Text) / 304.8
Case 2
lblen.Text = Textl1.Text
Case 3
lblen.Text = Val(Textl1.Text) / 1000
End Select
Case 3
Select Case cbolrlt.SelectedIndex
Case 0
lblen.Text = Val(Textl1.Text * 1000) / 308.4
Case 1
lblen.Text = Val(Textl1.Text * 1000) / 25.4
Case 2
lblen.Text = Val(Textl1.Text) * 1000
Case 3
lblen.Text = Textl1.Text
End Select
End Select
End Sub
End Class