游桂林象山作文600字:刚学VB问一个超简单的问题~~~

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 09:20:15
为什么下边的代码不能实现比较大小的功能啊~~~往高手给解释一下,教程上的我看了,但是为什么这个看起来合理的就不行呢~~
Private Sub click_command1()
Dim a As Single
Dim b As Single

a = Text1.Text
b = Text2.Text

If a > b Then
MsgBox "A大"
ElseIf a < b Then
MsgBox "B大"
Else
MsgBox "一样大"
End If
End Sub

把其中代码改为:
If a > b Then
MsgBox "A大"
End if
If a < b Then
MsgBox "B大"
end if
If a = b Then
MsgBox "一样大"
End If

Private Sub click_command1()
Dim a As Single
Dim b As Single

a =val(Text1.Text)
b = val(Text2.Text)

If a > b Then
MsgBox "A大"
ElseIf a < b Then
MsgBox "B大"
Else
MsgBox "一样大"
End If
End Sub

Text1.Text 类型是string吧,得转成single

类型问题,textbox里的是string类型

a=val(text1.text)