vb问题.火急

来源:百度知道 编辑:UC知道 时间:2024/05/27 09:10:50
小弟vb入门.想做个最简单得两数相加.可是困难重重.
请各位大叔大姐帮我看下问题出在那.我用得是vb6.0
-------------------------------------------------------------
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
Text1.Text = Val(Text2.Text) + Val(Text3.Text)
End If
End Sub

Private Sub Text1_Change()
Text1.Text = Val(Text2.Text) + Val(Text3.Text)
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim n As Integer, a As String
If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "." And Chr(KeyAscii) <> "-" And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
Dim n As Integer, a As String
If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "." And Chr(KeyAscii) <> "-" And KeyAscii <> 8 Then
KeyAscii = 0
End If
End S

这是根据你得改得

Private Sub Command1_Click()
Text1.Text = Val(Text2.Text) + Val(Text3.Text)
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim n As Integer, a As String
If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "." And Chr(KeyAscii) <> "-" And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
Dim n As Integer, a As String
If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "." And Chr(KeyAscii) <> "-" And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

直接用一个command1和两个text控件,一个标签控件labble1
然后在command1_click里添加如下代码:
labble1.caption=val(t1.text)+val(t2.text)