Home All Groups Group Topic Archive Search About

Question for the Wizards!!!

Author
13 May 2005 2:21 PM
Brian Shafer
I was asked yesterday, why I can't set a textbox to Null
me.textbox = Null

My reply was because it is a object and textbox is a properity?

and that I didn't really know for sure...

What is the correct answer?

Author
13 May 2005 2:30 PM
Ken Halter
"Brian Shafer" <Brian Sha***@discussions.microsoft.com> wrote in message
news:5028BC01-D342-44FB-9247-759C2FDE4321@microsoft.com...
>I was asked yesterday, why I can't set a textbox to Null
> me.textbox = Null
>
> My reply was because it is a object and textbox is a properity?
>
> and that I didn't really know for sure...
>
> What is the correct answer?

If you try to run this code....

Text1.Text = Null

....you'll get an Error 94, Invalid Use of Null. The msgbox will contain a
Help button. Clicking that brings you to a page that says....

"Null is a Variant subtype used to indicate that a data item contains no
valid data."

The way I read it is.... you can't set a textbox's Text property = no valid
data.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..
Author
13 May 2005 2:36 PM
Bob Butler
"Brian Shafer" <Brian Sha***@discussions.microsoft.com> wrote in
message news:5028BC01-D342-44FB-9247-759C2FDE4321@microsoft.com
> I was asked yesterday, why I can't set a textbox to Null
> me.textbox = Null
>
> My reply was because it is a object and textbox is a properity?
>
> and that I didn't really know for sure...
>
> What is the correct answer?

The default property of a textbox control is .Text which is a string so what
you are trying to do is
me.textbox.text = Null

A string can not be "Null" so the assignment will fail.  You can assign a
zero-length string
me.textbox.text = ""
or you can use the vbNullString constant (it's technically a misuse of the
constant but VB will accept it) but that will be treated the same as the
zero-length string

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
13 May 2005 3:48 PM
Stu
> or you can use the vbNullString constant (it's technically a misuse of the
> constant but VB will accept it) but that will be treated the same as the
> zero-length string

Why, technically,  is this the case?  I thought you should use constants in
place of popular strings when ever possible.

Cheers
Stu
Author
13 May 2005 3:54 PM
Bob Butler
"Stu" <saet@steh.szerg> wrote in message
news:O1BctN9VFHA.2692@TK2MSFTNGP15.phx.gbl
>> or you can use the vbNullString constant (it's technically a misuse
>> of the constant but VB will accept it) but that will be treated the
>> same as the zero-length string
>
> Why, technically,  is this the case?  I thought you should use
> constants in place of popular strings when ever possible.

You should, but vbNullstring is *not* the same as "" and is doumented as
being defined for use in calling external rocedures that need a Null pointer
instead of a zero-length string.  The fact that it ends up accomplishing the
same thing inside VB is a side-effect of the way it was implemented.

Had MS ever made a VB7 they would have been free to change that and code
that relied on it would stop working because it relied on undocumented,
unsupported techniques.  Since VB has died with VB6 it's a moot point.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

AddThis Social Bookmark Button