Solved

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

Posted on 2006-06-09
5
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 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