新建From1(窗体),新建Text1(TextBox),代码:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim strFind As String
strFind = f_Find(KeyAscii)
Text1.SelText = "" '去掉选择的
Text1.Text = Text1.Text & Chr(KeyAscii) & strFind '找到新的数据加入,这里可以变
Text1.SelStart = Len(Text1.Text) - Len(strFind)
Text1.SelLength = Len(Text1.Text)
KeyAscii = 0 '去掉输入的,否则就是两次输入了
End Sub
Private Function f_Find(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("1")
f_Find = "One"
Case Asc("b")
f_Find = "B"
Case Else
f_Find = "" '找不到就返回空
End Select
End Function
你希望按那个键 出现什么内容,就去 子程序 f_Find 里面判断返回,比如 可以查询 数据库。