'/对于INPUTBOX函数 , 头疼的是, 如果不填东东, OK和cancel的传回值是一样的
'/VB中的解释是“StrPtr:返回真正的UNICODE字符串缓冲区的地址”
'/利用这一特性,制作了这个有返回值的InputBox函数...
程序代码: | [ 复制代码 ] |
Option Explicit
'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
Public Function InputBoxQ(ByVal prompt As String, Optional ByVal title As String, Optional ByVal default As String, Optional cancel As Long, Optional ByVal xpos As Long, Optional ByVal ypos As Long, Optional ByVal helpfile As String, Optional ByVal context As Long) As String
'/cancel 参数就是代表返回值,返回为0表示选择了取消
'/其它参数和原来InputBox一样
InputBoxQ = InputBox(prompt, title, default, xpos, ypos, helpfile, context)
cancel = StrPtr(InputBoxQ)
End Function
Private Sub Command1_Click()
Dim lngQ As Long, strS As String
strS = InputBoxQ("asdfa", "sdfasf", , lngQ)
If lngQ = 0 Then
MsgBox "inputbox choosed cancel"
Else
MsgBox strS
End If
End Sub
'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
Public Function InputBoxQ(ByVal prompt As String, Optional ByVal title As String, Optional ByVal default As String, Optional cancel As Long, Optional ByVal xpos As Long, Optional ByVal ypos As Long, Optional ByVal helpfile As String, Optional ByVal context As Long) As String
'/cancel 参数就是代表返回值,返回为0表示选择了取消
'/其它参数和原来InputBox一样
InputBoxQ = InputBox(prompt, title, default, xpos, ypos, helpfile, context)
cancel = StrPtr(InputBoxQ)
End Function
Private Sub Command1_Click()
Dim lngQ As Long, strS As String
strS = InputBoxQ("asdfa", "sdfasf", , lngQ)
If lngQ = 0 Then
MsgBox "inputbox choosed cancel"
Else
MsgBox strS
End If
End Sub
相关链接:vb,,返回值,InputBox,函数
[本日志由 admin 于 2013-11-01 11:02 PM 编辑]
引用通告地址 (0):
http://www.cnng.net/blog/trackback.asp?tbID=66
http://www.cnng.net/blog/trackback.asp?tbID=66&CP=GBK
http://www.cnng.net/blog/trackback.asp?tbID=66
http://www.cnng.net/blog/trackback.asp?tbID=66&CP=GBK