在一个窗体内有Commandbutton1、CommandButton2、Text1.text、label1
希望在text1.text内输入1112时commandButton1、Commandbutton2能下沉,且label1上显示11、12。或按下CocommandButton1、Commandbutton2时text1.text内显示11或12,且label1上的11、12能自动变更!
最后一点要求是在text1.text内输入11时,如何不会回车就自动输入到变量中?
谢谢

解决方案 »

  1.   

    对于最后一点要求可以这样,定义一个模块级变量,然后在text德change事件中赋值Option Explicit
    Dim a As StringPrivate Sub Text1_Change()
    a = Text1.Text
    Debug.Print a
    End Sub
      

  2.   

    我来尝试回答一下
    可以在按下键盘时判断text1的内容是不是等于1112,如果等于就sendkey(需要事先设置好tab顺序,不知道能不能实现按下这个动作)同时label1显示内容。当按下command的时候就可以在text里显示了,label1改变(这个很简单)
      

  3.   

    您哪里看不明白?[email protected]
      

  4.   

    Commandbutton可能有十几个,我是说在Text内软件入11或者12时按钮能动作。当然也能输入21、31等数值。
    您知道怎么做到吗?
      

  5.   

    建议不要用command按钮
    改用check单选框,并把check的style属性设置成按钮形式
    设置多个同名的check的index属性为"11"、"12"、"13"、"21"、"22"、"23"……
    在Text1_Change()事件里判断text1的内容,并用mid两位两位地分割字符串,然后用一个select case判断各个子字符串(subtext)的内容,并用check(val(subtext)).value=1;lable1=subtext
    按下按钮时容易,用Check_Click(Index As Integer)事件就行了,text1=Index;label1=Index最后一点 chewinggum(口香糖·向星星前进) 说得不错,可照用。另外,根据需要,可在label1的change事件里恢复check按钮的凸起形状,即设置check(index).value=0,亦即模拟按钮效果。
      

  6.   

    注:……
    在Text1_Change()事件(建议选择text1_keyUP事件,避免与check的click事件改变text1时产生死循环。)里判断text1的内容,并用mid两位两位地分割字符串,然后
    ……
      

  7.   

    Private Sub Command1_Click()
        Text1.Text = "11"
        Label1.Caption = "11"
        MsgBox "click_1"
    End SubPrivate Sub Command2_Click()
        Text1.Text = "12"
        Label1.Caption = "22"
        MsgBox "click_2"
    End Sub
    Private Sub Text1_Change()
        If InStr(Text1.Text, "11") Then Call Command1_Click
        If InStr(Text1.Text, "12") Then Call Command2_Click
    End Sub
      

  8.   

    Private Sub Command1_Click()
        Text1.Text = "11"
        Label1.Caption = "11"
        MsgBox "click_1"
    End SubPrivate Sub Command2_Click()
        Text1.Text = "12"
        Label1.Caption = "22"
        MsgBox "click_2"
    End Sub
    Private Sub Text1_Change()
        If Text1.Text="1112") Then
             Call Command1_Click
             Call Command2_Click
       end if
       If Text1.Text= "11" Then str1=text1.text
    End Sub
      

  9.   

    新建一个记事本文件,把下面的全部代码贴入记事本中,把记事本的扩展名改为.frm,然后双击打开就可以看到效果了。
    VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   5295
       ClientLeft      =   60
       ClientTop       =   450
       ClientWidth     =   7710
       LinkTopic       =   "Form1"
       ScaleHeight     =   5295
       ScaleWidth      =   7710
       StartUpPosition =   3  'Windows Default
       Begin VB.TextBox Text1 
          Height          =   615
          Left            =   600
          MaxLength       =   18
          TabIndex        =   9
          Top             =   360
          Width           =   1455
       End
       Begin VB.CheckBox Check1 
          Caption         =   "33"
          Height          =   495
          Index           =   33
          Left            =   2400
          Style           =   1  'Graphical
          TabIndex        =   8
          Top             =   2760
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "32"
          Height          =   495
          Index           =   32
          Left            =   1680
          Style           =   1  'Graphical
          TabIndex        =   7
          Top             =   2760
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "31"
          Height          =   495
          Index           =   31
          Left            =   960
          Style           =   1  'Graphical
          TabIndex        =   6
          Top             =   2760
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "23"
          Height          =   495
          Index           =   23
          Left            =   2400
          Style           =   1  'Graphical
          TabIndex        =   5
          Top             =   2280
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "22"
          Height          =   495
          Index           =   22
          Left            =   1680
          Style           =   1  'Graphical
          TabIndex        =   4
          Top             =   2280
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "21"
          Height          =   495
          Index           =   21
          Left            =   960
          Style           =   1  'Graphical
          TabIndex        =   3
          Top             =   2280
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "13"
          Height          =   495
          Index           =   13
          Left            =   2400
          Style           =   1  'Graphical
          TabIndex        =   2
          Top             =   1800
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "12"
          Height          =   495
          Index           =   12
          Left            =   1680
          Style           =   1  'Graphical
          TabIndex        =   1
          Top             =   1800
          Width           =   735
       End
       Begin VB.CheckBox Check1 
          Caption         =   "11"
          Height          =   495
          Index           =   11
          Left            =   960
          Style           =   1  'Graphical
          TabIndex        =   0
          Top             =   1800
          Width           =   735
       End
       Begin VB.Label Label1 
          Height          =   495
          Left            =   2760
          TabIndex        =   10
          Top             =   480
          Width           =   2055
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    '===============================================
    '以下是源程序部分:
    '=================================================Dim Subtext(8) As StringPrivate Sub Check1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    checkup
    Text1 = Index
    Label1 = Index
    Check1(Index).Value = 0 '使按钮凸起
    Subtext(Left(Index, 1) * Right(Index, 1) - 1) = Index '保存text1的值
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    If 48 > KeyAscii Or KeyAscii > 51 Then KeyAscii = 0 '限制非法数字的输入
    End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    On Error Resume Next
    Dim Lentext As Integer, i As Integer
    Label1 = ""
    checkup
    Lentext = Len(Text1)
    If (Lentext Mod 2) = 0 Then
        For i = 0 To Lentext
            If i * 2 + 1 > Lentext Then Exit For
            Subtext(i) = Mid(Text1, i * 2 + 1, 2) '保存text1的值
            Check1(Val(Subtext(i))).Value = 1     '使按钮被“按下”
                If Label1 = "" Then
                   Label1 = Subtext(i)
                Else
                  Label1 = Label1 & "," & Subtext(i) '显示labelq
                End If
        Next
    End If
    End Sub
    Sub checkup()   '使按钮全部恢复凸起状态
    Check1(11).Value = 0
    Check1(12).Value = 0
    Check1(13).Value = 0
    Check1(21).Value = 0
    Check1(22).Value = 0
    Check1(23).Value = 0
    Check1(31).Value = 0
    Check1(32).Value = 0
    Check1(33).Value = 0
    End SubPrivate Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.SetFocus
    Text1.SelLength = Len(Text1)
    End Sub
      

  10.   

    楼上的朋友,首先先谢谢您。
    但你编的这个程序还是有点小问题,如不能在TEXT1.text内修改数值。而且当我用MOUSE按下11时,他不会下沉!
    谢谢!
    能告诉我您的信箱号码吗?
      

  11.   

    Private Sub Check1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    checkup
    Text1 = Index
    Label1 = Index
    Check1(Index).Value = 0 '使按钮凸起(把这一句去掉就会下沉了)
    Subtext(Left(Index, 1) * Right(Index, 1) - 1) = Index '保存text1的值
    End Sub
    修改数值可以的吧? 我不知你要怎样修改的, 我修改的时候好象没问题,呵呵
    这只是一个例程, 你运用时灵活点麻。
      

  12.   

    上文又错了,呵呵,应该改为“1”
    Check1(Index).Value = 1 '使按钮凸起(把这一句去掉就会下沉了)
      

  13.   

    只看懂最后一个要求
    dim n as str
    private sub text1_change()
     n=text1.text
    msgbox n,vbokonlly
    end sub
      

  14.   

    你是不是指按退格键时删除不了文本框中的内容?
    如果是,在keypress里加一条语句允许keyascii=8通过就行了
    程序部份你用下面这一段吧,它或者比前面的版本要好点
    '===============================================
    '以下是源程序部分:
    '=================================================Dim Subtext(8) As StringPrivate Sub Check1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    checkup
    Text1 = Index
    Label1 = Index
    Check1(Index).Value = 1 '使按钮凸起
    Subtext(Left(Index, 1) * Right(Index, 1) - 1) = Index '保存text1的值
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 8 Then
    If 48 > KeyAscii Or KeyAscii > 51 Then KeyAscii = 0 '限制非法数字的输入
    End If
    End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    On Error Resume Next
    Dim Lentext As Integer, i As Integer, temptext As String
    Label1 = ""
    checkup
    Lentext = Len(Text1)
    temptext = Text1
    If (Lentext Mod 2) <> 0 Then temptext = Left(Text1, Lentext - 1)
    For i = 0 To Lentext - 1
            If i * 2 + 1 > Lentext Then Exit For
            Subtext(i) = Mid(temptext, i * 2 + 1, 2) '保存text1的值
            Check1(Val(Subtext(i))).Value = 1     '使按钮被“按下”
                If Label1 = "" Then
                   Label1 = Subtext(i)
                Else
                  Label1 = Label1 & "," & Subtext(i) '显示labelq
                End If
        Next
    'End If
    End Sub
    Sub checkup()   '使按钮全部恢复凸起状态
    Check1(11).Value = 0
    Check1(12).Value = 0
    Check1(13).Value = 0
    Check1(21).Value = 0
    Check1(22).Value = 0
    Check1(23).Value = 0
    Check1(31).Value = 0
    Check1(32).Value = 0
    Check1(33).Value = 0
    End SubPrivate Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.SetFocus
    Text1.SelLength = Len(Text1)
    End Sub