Link to home
Start Free TrialLog in
Avatar of Stapman
Stapman

asked on

If with Variant-type

I have a Variant type which can become to an Integer, a String a Null in my Sub.

I use "If 'variable' Then" and go over the "else" statement to run the source code in case of my 'variable' being "Null".

This works good when 'variable' is an integer - the "if"-clause is "true" - but when 'variable' is a string the error #13 arises (type problem...).

Thanks for your support!
Avatar of Stapman
Stapman

ASKER

Edited text of question.
Stapman,

I'm not sure that I have understood you correctly. Here is an attempt, though. There is an IsNull function that may help. You can also try the IsEmpty function that returns True if the variant variable has not been assigned a value.

If IsNull(x) Then ...

Ture Magnusson
Karlstad, Sweden
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim Condition As Variant

Condition = 1
If Condition Then MsgBox "True"

Condition = "1"
If CInt(Condition) Then MsgBox "True"

Condition = Null
If IsNull(Condition) Then MsgBox "True"
Avatar of Stapman

ASKER

Thanks for your quick and detailed answer(s). Thanks to SLE too!