|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Question for the Wizards!!!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? "Brian Shafer" <Brian Sha***@discussions.microsoft.com> wrote in message If you try to run this code....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? 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.. "Brian Shafer" <Brian Sha***@discussions.microsoft.com> wrote in The default property of a textbox control is .Text which is a string so whatmessage 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? 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..." > or you can use the vbNullString constant (it's technically a misuse of the Why, technically, is this the case? I thought you should use constants in> constant but VB will accept it) but that will be treated the same as the > zero-length string place of popular strings when ever possible. Cheers Stu "Stu" <saet@steh.szerg> wrote in message You should, but vbNullstring is *not* the same as "" and is doumented asnews: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. 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..."
Other interesting topics
|
|||||||||||||||||||||||