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...
Sub test()
Dim S$, sMsg$
S = InputBox("Enter anything or nothing:")
If StrPtr(S) = 0 Then
sMsg = "You cancelled"
Else
sMsg = "StrPtr value: " & StrPtr(S)
sMsg = sMsg & vbLf & "You pressed Enter: " & (S = vbNullString)
sMsg = sMsg & vbLf & "You entered: " & Chr(34) & S & Chr(34)
End If
MsgBox sMsg
End Sub
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic
VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.
vb.general.discussion