用Private Sub Text_change()来触发事件。把从TEXT输入的值赋给一个变量,当变量发生变化时就触发事件。

解决方案 »

  1.   

    Option Explicit
    Public t4 As Integer 'text4中的内容Private Sub Form_Load()
        t4 = text4.Text
    End SubPrivate Sub Text2_Change()
        If Val(text3.Text) > Val(text2.Text) Then
            text4.Text = t4 * 0.03
        Else
            text4.Text = t4 * 0.04
        End If
    End SubPrivate Sub text3_Change()
        If Val(text3.Text) > Val(text2.Text) Then
            text4.Text = t4 * 0.03
        Else
            text4.Text = t4 * 0.04
        End If
    End Sub
      

  2.   

    我建议你用lostfocus事件,如果用change事件的话,你还没有完全输入完,事件就已发生,这是没有意义的。Private Sub Text2_LostFocus()
    If Val(Text3.Text) > Val(Text2.Text) Then
        Text4.Text = Str(Val(Text4.Text) * 0.03)
    Else
        Text4.Text = Str(Val(Text4.Text) * 0.04)
    End If
    End Sub
    Private Sub Text3_LostFocus()
    If Val(Text3.Text) > Val(Text2.Text) Then
        Text4.Text = Str(Val(Text4.Text) * 0.03)
    Else
        Text4.Text = Str(Val(Text4.Text) * 0.04)
    End If
    End Sub