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