View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1891_] Rick Rothstein \(MVP - VB\)[_1891_] is offline
external usenet poster
 
Posts: 1
Default Is there a test for an empty string that returns a boolean?

CboElevation.Enabled = IsEmpty(ElevCptn)

IsEmpty() isn't for strings, it's for Variants that haven't been assigned
a value. IsMissing(), as Peter suggested, is only for Variants. Optional
parameters typed as anything besides a Variant that aren't given a default
value in the procedure declaration get the default for the data type, so
numbers get 0 and strings get empty strings. Therefore you should simply
be able to test ElevCptn against "". Did you ever try that?

Ron's Len() suggestion is also valid.


And to follow up on Jeff's comment, while this may look "simpler"...

CboElevation.Enabled = (ElevCptn = "")

due to the way VB stores Strings, this is marginally faster...

CboElevation.Enabled = (Len(ElevCptn) = 0)

It wouldn't matter in a single or few usage situation; but, inside a very
large loop, it could make a difference.

Rick