有关vb中的val的疑问

来源:百度知道 编辑:UC知道 时间:2024/05/13 16:00:24
我想问一下,val是有什么用的?像下面两个都能正常运行,一个有val,一个没有,有什么区别的 ?

Private Sub Command1_Click()
dim inttext as integer
select case inttext
Case Is = 10
Text2.Text = "is10"
Case Else
Text2.Text = "no"
End Select
End Sub

Private Sub Command1_Click()
Select Case Text1
Case Is = 10
Text2.Text = "is10"
Case Else
Text2.Text = "no"
End Select
End Sub
第一个写少了一句,应该是这个
Private Sub Command1_Click()
dim inttext as integer
inttext=val(text1.text)
select case inttext
Case Is = 10
Text2.Text = "is10"
Case Else
Text2.Text = "no"
End Select
End Sub

你事先定义了inttext 是一个整数,val()是求值的意思.val(text1.text) 求的是text1.text的值,运算结果也是一个整数,这样就保证了等号两边是相同类型的数据.像Text2.Text = "is10" 是属于给Text2.Text 赋上语句"is10",所以不能用val(),因为它不是一个数,而是语句