盈彩体育注册(中国)有限公司 | 您所在的位置:网站首页 › 盈彩体育注册(中国)有限公司 › VB TIP: InputBox |
Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More. 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. CodeDim strInput As StringstrInput = InputBox("Enter something:")If StrPtr(strInput) =ThenMsgBox "You pressed cancel!"End If |
CopyRight 2018-2019 盈彩体育注册(中国)有限公司 版权所有 豫ICP备16040606号-1 |