InputBox - OK or Cancel?
You display an InputBox. But did the user press Cancel - or OK without entering anything? If you thought there was no way to tell the difference, you注释:re wrong.
You see, if the user presses cancel, vbNullString is returned. However if they press OK, the empty string ("") is sent back. But in Visual Basic, vbNullString equates to an empty string, so you can注释:t compare the two - even though in reality, they注释:re completely different.
However you can use the StrPtr (注释:string pointer注释:) function to determine whether the return string is indeed a vbNullString - as by definition, a vbNullString 注释:pointer注释: is zero.
And this code demonstrates how to do that.
Code
Dim strInput As String
strInput = InputBox("Enter something:")
If StrPtr(strInput) = 0 Then
MsgBox "You pressed cancel!"
End If
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073










