将andymark的例子改成了函数,方便大家调用:
Type InputInfo
Value As String
Buttons As Integer
End Type
Public Function MyInputBox(Message As String, Optional Title As String = "请输入参考值:", Optional Default As String = "") As InputInfo
Dim strValue As String
Dim blnCancel As Boolean
strValue = InputBox(Message, Title, Default)
blnCancel = CBool(StrPtr(strValue))
If blnCancel Then
MyInputBox.Buttons = vbOK
MyInputBox.Value = strValue
Else
MyInputBox.Buttons = vbCancel
MyInputBox.Value = ""
End If
End Function
调用例子:
Private Sub Command1_Click()
Dim intButtons As Integer
Dim MyInfo As InputInfo
MyInfo = MyInputBox("你好")
intButtons = MyInfo.Buttons
If intButtons = vbOK Then
MsgBox "你按了'确定'键"
MsgBox "你输入的是:" & MyInfo.Value
Else
MsgBox "你按了'取消'键"
End If
End Sub
[此贴子已经被作者于2006-10-27 10:16:17编辑过]
|