?
Solved

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

Posted on 2006-06-09
5
Medium Priority
?
205 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 200 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Suggested Courses

840 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