常量定义错了
Public Const CB_FINDSTRING = &H18F

解决方案 »

  1.   

    对不起,你的常量定义没有错你找不到的原因是:SendMessage函数的最后参数lParam as Any必须使用Byval,你现在是将字符串放进去了,而在VB里面这样做就是使用了指针,当然找不到了以下是源代码,已经测试过,可以找得到的。
    Option Explicit
    '(需要一个Combo1和一个Text1)
    Private Const LB_FINDSTRING = &H14C
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As LongPrivate Sub Form_Load()
       Combo1.AddItem "aaa"
       Combo1.AddItem "bbb"
       Combo1.AddItem "vvv"
       Combo1.AddItem "ccc"
       Combo1.AddItem "ddd"
       Combo1.AddItem "eee"
    End SubPrivate Sub Text1_Change()
       Combo1.ListIndex = SendMessage(Combo1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
    End Sub祝你好运!
      

  2.   

    'yes, like  hereticclub(雪狐), run this
    'form codeVERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3195
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   3  'Windows Default
       Begin VB.TextBox Text1 
          Height          =   285
          Left            =   240
          TabIndex        =   1
          Text            =   "Text1"
          Top             =   975
          Width           =   1050
       End
       Begin VB.ComboBox cbo 
          Height          =   315
          Left            =   270
          TabIndex        =   0
          Text            =   "cbo"
          Top             =   375
          Width           =   1890
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Sub Form_Load()
        cbo.AddItem ("abc")
        cbo.AddItem ("bcd")
        cbo.AddItem ("cde")
        cbo.AddItem ("def")
        cbo.AddItem ("efg")
        cbo.AddItem ("fgh")
        cbo.AddItem ("ghi")
        cbo.AddItem ("hij")
    End SubPrivate Sub Text1_Change()
        aa = Trim(Text1.Text)
        bb = cbo.hwnd
        cbo.ListIndex = index(aa, bb)
    End Sub'module code
    Attribute VB_Name = "Module1"
    Option ExplicitPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Const CB_GETCOUNT = &H146Public Const CB_FINDSTRING = &H14C
    Public aa As String
    Public bb As Long
    Public Function index(aa As String, bb As Long) As Long
        index = SendMessage(bb, CB_FINDSTRING, -1, ByVal CStr(Form1.Text1.Text))
        Debug.Print index
    End Function