CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 1999
    Location
    India
    Posts
    11

    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.


  2. #2

    Re: knowing the Control Type dynamically.

    Try TypeName(Controls(3)). The TypeName function returns the Object Type when passed an object.


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    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
  •  





Click Here to Expand Forum to Full Width

Featured