How to get control type in VB?

Can anyone help me or share ideas on how to get the control type in VB6? Your help is Appreciated. Thanks in Advance.

Comments

  • : Can anyone help me or share ideas on how to get the control type in VB6? Your help is Appreciated. Thanks in Advance.
    :

    I think the [b]TypeOf[/b] keyword is what you are looking for.

    (Note this is VB.NET code, so the example might now work, but the TypeOf keyword is the same in VB6)

    [code]
    Dim x As Button
    x = New Button()
    If TypeOf x Is Control Then
    ' Insert code to continue program execution.
    End If
    [/code]

    Best Regards,
    Richard

  • BitByBit_Thor is correct, however he is right it is not the same as VB.NET ...

    [code]
    Option Explicit

    Private WithEvents mSomeCommand As CommandButton

    Private Sub Form_Load()
    Set mSomeCommand = Controls.Add("VB.CommandButton", "SomeCommand")

    If TypeOf mSomeCommand Is CommandButton Then
    MsgBox "Is Command Button"
    End If

    If TypeOf mSomeCommand Is Control Then
    MsgBox "Is Control"
    End If
    End Sub
    [/code]

    It is strange that VB6 does not support direct inheritence when designing classes, yet there is exceptions hardcoded right into the product. For instance, in the example above, it is clear that Control is a base class of CommandButton.


    : : Can anyone help me or share ideas on how to get the control type in VB6? Your help is Appreciated. Thanks in Advance.
    : :
    :
    : I think the [b]TypeOf[/b] keyword is what you are looking for.
    :
    : (Note this is VB.NET code, so the example might now work, but the TypeOf keyword is the same in VB6)
    :
    : [code]
    : Dim x As Button
    : x = New Button()
    : If TypeOf x Is Control Then
    : ' Insert code to continue program execution.
    : End If
    : [/code]
    :
    : Best Regards,
    : Richard
    :
    :

  • :
    : It is strange that VB6 does not support direct inheritence when designing classes, yet there is exceptions hardcoded right into the product. For instance, in the example above, it is clear that Control is a base class of CommandButton.
    :
    :

    Then it's fairly reasonable to say that VB 'knows' inheritence, but that when designing such features are disabled. They want to force you to use Interfaces if a situation calls for it, rather than Inheritence.
    But yeah it's kinda strange and the reason that VB6 isn't fully OOP.

    Best Regards,
    Richard

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories