View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Cancel Input Box error

"GS" skrev i melding
...
Opposed to other variables, VBA will not know how much memory a
String will need. So what it does when a string is used is to save
it "somewhere/anywhere available" and put a pointer, the address
to the text, i variable S. When you cancel, the string is not used
and the stringpointer, StrPtr, remains zero.


Harald,
Thanks for sharing an 'old trick'; these are always welcome!

Unfortunately, it doesn't work when users "enter nothing" because
doing so (leave empty, hit Enter key) returns an empty string (or
vbNullString) and so StrPtr is not zero...


I must have explained myself poorly. This is the whole point,
separating cancelling from entering nothing. Entering nothing is a
valid input in many operations.This works.

Best wishes Harald


Good point! It makes sense then to...

If StrPtr < 0 And sz = vbNullString

...so we know user didn't cancel. I like it!! Thanks for sharing this...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion