Private Sub Text19_Change() If Text19 = 0.3 Then Text2 = 143.37 Text3 = 143.37 r = 2133.7 ElseIf Text = 0.25 Then Text2 = 138.8 Text3 = 138.8 r = 2147.8 End If End Sub
Private Sub Text19_KeyPress(KeyAscii As Integer) '当在文本框中按回车键时 If KeyAscii = 13 Then If CDbl(Text19.Text) = 0.3 Then Text2.Text = "143.37" Text3.Text = "143.37" r = 2133.7 ElseIf CDbl(Text.Text) = 0.25 Then Text2.Text = "138.8" Text3.Text = "138.8" r = 2147.8 End If End If End Sub
我之前已经有一段代码了 Private Sub Text19_KeyPress(KeyAscii As Integer) Dim s, ss As String Select Case KeyAscii Case 48 To 57, 46, 8 s = Right$(Text19.Text, 3) ss = Left$(s, 1) If ss = "." Then If KeyAscii <> 8 Then KeyAscii = 0 End If End If Case Else: KeyAscii = 0 End Select End Sub 而且有没有 不按回车 随着输入随时改变的方法呢
Dim a, b, c As IntegerPrivate Sub Form_Load() Text1.Text = 0 Text2.Text = 0 Text3.Text = 0 End SubPrivate Sub Timer1_Timer()If Text1.Text = 1 Then Text2.Text = 143.37 Text3 = 143.37 ElseIf Text1.Text = 2 Then Text2.Text = 746 Text3.Text = 213 End If End Sub
Private Sub Text19_KeyPress(KeyAscii As Integer) If CDbl(Text19.Text) = 0.3 Then Text2.Text = "143.37" Text3.Text = "143.37" r = 2133.7 ElseIf CDbl(Text.Text) = 0.25 Then Text2.Text = "138.8" Text3.Text = "138.8" r = 2147.8 End If End Sub这就可以,但是你前面的一段代码: Select Case KeyAscii
Case Else: KeyAscii = 0 ‘此句应去掉
用文本框的change事件,如 Private Sub Text1_Change() Text2 = Text1 End Sub text2内容随text1改变
其实你text19_keypress过程中不用去那一句也可以,你只需要把一些代码放到change就可以了 Private Sub Text19_Change() If Text19.text = 0.3 Then Text2.text = 143.37 Text3.text = 143.37 r = 2133.7 ElseIf Text19.text = 0.25 Then Text2.text = 138.8 Text3.text = 138.8 r = 2147.8 End If End Sub 另外,keypress事件为了判别是否有两个“.”加入一行代码即可,改动如下: Private Sub Text19_KeyPress(KeyAscii As Integer) Dim s, ss,sss As String Select Case KeyAscii Case 48 To 57, 46, 8 s = Right$(Text19.Text, 3) ss = Left$(s, 1) sss = Right$(s, 1) If KeyAscii = 46 Then If sss = "." Then KeyAscii = 0 End If End If If ss = "." Then If KeyAscii <> 8 Then KeyAscii = 0 End If End If Case Else: KeyAscii = 0 End Select End Sub
If Text19 = 0.3 Then
Text2 = 143.37
Text3 = 143.37
r = 2133.7
ElseIf Text = 0.25 Then
Text2 = 138.8
Text3 = 138.8
r = 2147.8
End If
End Sub
'当在文本框中按回车键时
If KeyAscii = 13 Then
If CDbl(Text19.Text) = 0.3 Then
Text2.Text = "143.37"
Text3.Text = "143.37"
r = 2133.7
ElseIf CDbl(Text.Text) = 0.25 Then
Text2.Text = "138.8"
Text3.Text = "138.8"
r = 2147.8
End If
End If
End Sub
Private Sub Text19_KeyPress(KeyAscii As Integer)
Dim s, ss As String
Select Case KeyAscii
Case 48 To 57, 46, 8
s = Right$(Text19.Text, 3)
ss = Left$(s, 1)
If ss = "." Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
Case Else: KeyAscii = 0
End Select
End Sub
而且有没有 不按回车 随着输入随时改变的方法呢
Text1.Text = 0
Text2.Text = 0
Text3.Text = 0
End SubPrivate Sub Timer1_Timer()If Text1.Text = 1 Then
Text2.Text = 143.37
Text3 = 143.37
ElseIf Text1.Text = 2 Then
Text2.Text = 746
Text3.Text = 213
End If
End Sub
If CDbl(Text19.Text) = 0.3 Then
Text2.Text = "143.37"
Text3.Text = "143.37"
r = 2133.7
ElseIf CDbl(Text.Text) = 0.25 Then
Text2.Text = "138.8"
Text3.Text = "138.8"
r = 2147.8
End If
End Sub这就可以,但是你前面的一段代码:
Select Case KeyAscii
Case Else: KeyAscii = 0 ‘此句应去掉
Private Sub Text1_Change()
Text2 = Text1
End Sub
text2内容随text1改变
Private Sub Text19_Change()
If Text19.text = 0.3 Then
Text2.text = 143.37
Text3.text = 143.37
r = 2133.7
ElseIf Text19.text = 0.25 Then
Text2.text = 138.8
Text3.text = 138.8
r = 2147.8
End If
End Sub
另外,keypress事件为了判别是否有两个“.”加入一行代码即可,改动如下:
Private Sub Text19_KeyPress(KeyAscii As Integer)
Dim s, ss,sss As String
Select Case KeyAscii
Case 48 To 57, 46, 8
s = Right$(Text19.Text, 3)
ss = Left$(s, 1)
sss = Right$(s, 1)
If KeyAscii = 46 Then
If sss = "." Then
KeyAscii = 0
End If
End If
If ss = "." Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
Case Else: KeyAscii = 0
End Select
End Sub