|
-
September 29th, 1999, 02:33 PM
#1
knowing the Control Type dynamically.
Hi All,
Recently I was programming in VB and I came across a requirement. I wanted to know programatically what type each control is in a screen . Suppose a form has a command button, a checkbox, a textbox and a listbox. In my program code ( say open window event of the form) I want to know what type of control is Controls(3). I adressed the problem in an indirect way by naming the controls in a predefined format (e.g all textbox controls were named as txt...). In the program I checked controls(i).name . Can anybody give me a more general solution to this problem. If it is not possible in VB can VC++ handle this situation more gracefully ?
Thanking you in advance.
Parthasarathi.
-
September 29th, 1999, 03:55 PM
#2
Re: knowing the Control Type dynamically.
Try TypeName(Controls(3)). The TypeName function returns the Object Type when passed an object.
-
September 29th, 1999, 04:00 PM
#3
Re: knowing the Control Type dynamically.
Hi
You can check the type of each control on your form by using either the TypeName function that returns a string of the control's type, or the 'TypeOf .. Is ..' command, eg:
Dim ctl as Control
for Each ctl In me.Controls
Debug.print TypeName$(ctl)
If TypeOf ctl is TextBox then
' DO something
ElseIf TypeOf ctl is CommandButton then
' Do something else
'
' etc.
End If
next
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|