Dim IfChange As Boolean Private Sub TextBox1_Change() If IfChange Then IfChange = False If IsNumeric(Me.TextBox1.Value) Then Me.TextBox2.Value = Me.TextBox1.Value + 5 Else Me.TextBox2.Value = 0 End If IfChange = True End If End Sub
Private Sub TextBox2_Change() If IfChange Then IfChange = False If IsNumeric(Me.TextBox2.Value) Then Me.TextBox1.Value = Me.TextBox2.Value - 5 Else Me.TextBox1.Value = 0 End If End If End Sub
建议添加 Ifchange变量控制修改的进入问题。change属性经常使程序混乱。你监视一下运行过程就会明白。
谢谢指导~!!但还有点小疑问,我把里面公式变为了:
Me.Text2 = Me.Text1 * 9550 / 450 Me.Text1 = Me.Text2 * 450 / 9550
之后我在Text1中输入了“5”,就下面这样显示了,要加点什么东西来控制吗??
我按三楼的方法写如下:请教怎么我运行不出来,哪里错了吗?求助一下~!!
Dim IfChange As Boolean
Private Sub Text1_Change() If IfChange Then IfChange = False If IsNumeric(Me.Text1) Then Me.Text2 = Me.Text1 + 5 Else Me.Text2 = 0 End If IfChange = True End If End Sub
Private Sub Text2_Change() If IfChange Then IfChange = False If IsNumeric(Me.Text2) Then Me.Text1 = Me.Text2 - 5 Else Me.Text1 = 0 End If IfChange = True End If End Sub
注:我才学会了点VB而已,见笑了。。