Solved

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

Posted on 2006-06-09
5
198 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
ID: 16870823
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
ID: 16870923
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
ID: 16871067
>.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
ID: 16873120
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
ID: 16876718
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

911 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

21 Experts available now in Live!

Get 1:1 Help Now