Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I know the type of the controls?

Posted on 1999-08-09
15
Medium Priority
?
142 Views
Last Modified: 2010-04-30
Are there any property in the controls of VB that say me what kind of control is it? (If the control is a textbox, checkbox...)
0
Comment
Question by:abautistat
[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
  • 4
  • 4
  • 3
  • +4
15 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 1530694
If TypeOf Text1 Is TextBox Then MsgBox "fred"
0
 
LVL 22

Expert Comment

by:ture
ID: 1530695
abautistat,

* TypeName returns the name of a control as a string and can be used anyway you like.
* TypeOf is always used as part of an If statement.

Here is a procedure that shows both these ways to work with the control type.

Private Sub Command1_Click()
  Dim ctl As Control
 
  'Loop through all controls and display their TypeName
  For Each ctl In Form1.Controls
    MsgBox TypeName(ctl)
  Next ctl
 
  'Loop through all controls.
  'If the control is a TextBox, display it's text property
  For Each ctl In Form1.Controls
    If TypeOf ctl Is TextBox Then
      MsgBox ctl.Text
    End If
  Next ctl

End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 2

Expert Comment

by:sets
ID: 1530696
Private Sub Command1_Click()
  Dim ctl As Control
   
  'Loop through all controls and display their TypeName
  For Each ctl In Form1.Controls
    MsgBox TypeName(ctl)
  Next ctl
   
  'Loop through all controls.
  'If the control is a TextBox, display it's text property
  For Each ctl In Form1.Controls
    If TypeOf ctl Is TextBox Then
      MsgBox ctl.Text
    End If
  Next ctl

End Sub


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:ture
ID: 1530697
abautistat,
Please note that sets has posted an answer which is nothing but an exact copy of the code I provided as a comment.
/Ture
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1530698
Not only that but SETS is a phony account just set up today...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1530699
bad boy/girl? sets... ;))
0
 

Author Comment

by:abautistat
ID: 1530700
You are right Ture
Sets copy your comment.
Ture, how can I give you the points?
0
 
LVL 10

Accepted Solution

by:
smegghead earned 400 total points
ID: 1530701
What about me ?? I told you first !!!!   sulk sulk !
0
 
LVL 22

Expert Comment

by:ture
ID: 1530702
abautistat,

smegghead is right. He was first to tell you about using TypeOf, which works well in an If...Then statement. I added some information about TypeName also, which is useful in many other cases.

To give smegghead the points, please post a comment here, inviting him to post an answer for you to grade. If you prefer to give me the points, perhaps because of my additional information about TypeName, please invite me again to post an answer.

After your invitation, when someone has posted an answer, you can grade it to give the points to the answerer.

/Ture
0
 

Author Comment

by:abautistat
ID: 1530703
Ture, here you are your points
0
 

Author Comment

by:abautistat
ID: 1530704
Sorry ture you are right again...
smegghead thank you for your help...
Please answer the question. I will give you the points

0
 
LVL 10

Expert Comment

by:smegghead
ID: 1530705
Whhhaaaa whaaaaa whaaaaa... oh, I'll get over it...

all yours ture !!!!
0
 
LVL 2

Expert Comment

by:Bodya
ID: 1530706
Nice discussion, guis
But I think it would be polite to give smbd his (her) points or delete this quest. out of here.
0
 
LVL 10

Expert Comment

by:smegghead
ID: 1530707
Who is supposed to be claiming them ???
0
 

Author Comment

by:abautistat
ID: 2161827
Sorry for delay, but I haven't mark the bottom check box and I forgot it...

Thank you again...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 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