我做一个程序,有一个文本框,在里面输入不同的数据,另外两个文本框要相应的改变数据。请问 我该怎么做。文本框改变时 加入代码是不行的。。

解决方案 »

  1.   

    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
      

  2.   

    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
      

  3.   

    我之前已经有一段代码了
    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
    而且有没有 不按回车 随着输入随时改变的方法呢
      

  4.   

    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
      

  5.   

    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 ‘此句应去掉
      

  6.   

    用文本框的change事件,如
    Private Sub Text1_Change()
        Text2 = Text1
    End Sub
    text2内容随text1改变
      

  7.   

    我现在尝试用text文本做了一个简单的二位数组数据库。把文本框(即text19)当作输入索引的值。当输入文本框(text19)中的值不同时,得到相应的值,并向另外两个文本框(text2、text3)赋值。现在试一下去掉Case Else: KeyAscii = 0看看什么效果,之前没发现那句。。看看改完之后那另外两个文本框的值 是不是随着text19的变化而变化。
      

  8.   

    okok  去掉那句之后可以了,但是我想问一下 能不能不用按回车键 随着text19输入,text2和text3就相应的变化呢!我的程序中text19为数据索引项的值,让数据库中另外两个值 赋给text2和text3。怎么样才能随着text19输入的变化,text2、3直接发生相应的变化呢。
      

  9.   

    那把代码放到text19_change事件 中就可以了
      

  10.   

    其实你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