"VBA Study" How to determine a variable with a value of NULL in the IF

Source: Internet
Author: User

Iamlaosong

To do a tool requires the user to select in the list box, and then do the appropriate action, if you do not choose, to give hints, debugging found, take the value of the list box, if you do not choose, this value is null (empty), it is not normal to judge it, such as the following statement:

StationName = Listbox2.value
If Stationname=vbnullstring Then

Debugging found that the above if conditions whether with "=" or "<>" are not established, with Len (stationname) =0 is also not established, because at this time the variable stationname value is null, meaning empty, It can be understood that there is no assignment, although there is no value, but it is not a length of 0 string vbnullstring, judge it is not equal to vbnullstring is not established, for such a variable needs to use the following way to judge:

StationName = Listbox2.value
If IsNull (StationName) Then
msg = MsgBox ("Please select a gas station first!") ", vbOKOnly + vbexclamation," Iamlaosong ")
Exit Sub
End If

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"VBA Study" How to determine a variable with a value of NULL in the IF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.