|
-
Jun 30th, 2005, 09:46 AM
#1
Thread Starter
Frenzied Member
Something I didn't know - default property & Null
Sorry if this should be posted in a different forum; mods can move it if they want.
Lots of times you can leave off a control's default property when referring to the control, i.e. strFoo = txtBar instead of strFoo = txtBar.Text. Supposedly, this is a little faster, according to my VB5 textbook years ago.
But I didn't know until today that if, say, the textbox is empty, that method throws error 94, Invalid Use of Null. If I use txtBar.Text, it works fine, returning an empty string.
I know I could use Nz() to check the value, but it's easier to just add .Text.
Tengo mas preguntas que contestas
-
Jun 30th, 2005, 11:13 AM
#2
Re: Something I didn't know - default property & Null
Which app did you experience this with?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 30th, 2005, 11:20 AM
#3
Thread Starter
Frenzied Member
Re: Something I didn't know - default property & Null
Sorry, Access 2K.
Maybe using the default property makes Access treat the property as a variant, rather than text or a string?
Tengo mas preguntas que contestas
-
Jun 30th, 2005, 11:25 AM
#4
Re: Something I didn't know - default property & Null
Or could it be that your setting a field = to the textbox? Is the textbox a bould control?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 30th, 2005, 11:48 AM
#5
Thread Starter
Frenzied Member
Re: Something I didn't know - default property & Null
Nope. Unbound controls. The type of code that throws the error is strAns2 = txtAns2, if txtAns2 is empty. txtAns2.Text works, empty or not.
Maybe it's me. I get weird stuff sometimes, like a project called "utility" that once in a while appears as a 2nd project in the Project Explorer window. That has two forms, autodial and zoomform, & 4 modules, none of which are viewable. next time, the project may have disappeared.
Tengo mas preguntas que contestas
-
Jun 30th, 2005, 06:09 PM
#6
Re: Something I didn't know - default property & Null
Nope, it is a recreatable error. I did this and I got error 94. I guess there is no default property if the textbox
doesnt have the focus. If it has focus then the text property should return a nullstring instead of a Null.
VB Code:
Dim str As String
'str = Forms![Form1]![txtTextBox]
str = Null '<same error as the line above
MsgBox str
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 1st, 2005, 07:17 AM
#7
Thread Starter
Frenzied Member
Re: Something I didn't know - default property & Null
It happens even when the focus is set to the textbox. If it's empty, and no .Text, error 94 pops up. It's not a bug, it's an undocumented feature...
Tengo mas preguntas que contestas
-
Jul 1st, 2005, 10:19 AM
#8
Re: Something I didn't know - default property & Null
Yes, a undocumented feature. 
But if you try to do this you obviously understand the error - "str = Null" - Invalid use of Null.
So if the textbox is empty and you dont include the property then consider it as a Null.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|