Solved

Difference between refencing a text box directly and using it's "Text" property

Posted on 2006-06-09
5
197 Views
Last Modified: 2010-04-30
Hi all,

  Could someone please tell me the difference (if any) between referencing a text box directly as opposed to using its text property?  For example, if I have a text box called txtExample, and I want to retrieve whatever value the user has entered from this box, I can use the following code:

  Dim Example As String
  Example = txtExample

  I can also use:

  Dim Example As String
  Example = txtExample.Text

  Is there any difference between these two?  Thank you in advance.
0
Comment
Question by:potterlu
5 Comments
 
LVL 13

Accepted Solution

by:
rettiseert earned 50 total points
Comment Utility
Hi

Most controls in VB have a default property to let you abreviate your code, if the control has a default property then you can just type the name of the control and VB will assume that you are refering to the default property.

.Text is the default property of a text box so writing txtexample or txtexample.text is the same.
0
 
LVL 1

Expert Comment

by:Apyreal
Comment Utility
rettiseert is right. They are the same, but using the .Text property makes it easier to read and helps avoid confusion.
0
 
LVL 9

Expert Comment

by:dancebert
Comment Utility
>.Text is the default property of a text box so writing txtexample or txtexample.text is the same.

Some former Access programers will disagree, but they're wrong.  In Access 97 when the textbox is empty vartype(me.text1.text) = 8, but vartype(me.text1) = 1  (8 is String, 1 is NULL).  In VB, both cases return 8.
0
 
LVL 3

Expert Comment

by:J_K_M_A_N
Comment Utility
Just recently I had a problem though using the txtExample without the .text. I had a program that was for sending out email and I had a reference to the Outlook 9.0 object library and when I tried to use the following command:

oMsg.Attachments.Add txtAttachment1

It gave me an error number of -1940783101 and it said "The property does not exist. The field you want to modify is not valid for this type of item."

I had to add the .text to the end of it then it worked fine.

Just a word of warning.

J_K_M_A_N
0
 
LVL 18

Expert Comment

by:Sethi
Comment Utility
If you do not use a ".Text" property or any default property of a control then the code execution is faster. This is what I read several years back when I started my VB programming and I have been following this practice. I tried seraching the link, but Vb.net is everywhere :-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now