2 Replies - 3874 Views - Last Post: 10 August 2011 - 03:12 PM Rate Topic: -----

#1 saumitrapaul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 20-July 11

Select Case TypeOf Control Possible?

Posted 09 August 2011 - 10:51 PM

Dear Friend,

I am trying to write code as the following-


For Each ControlObject As Control In Me.Controls
    Select Case TypeOf ControlObject

         Case TextBox

         Case ComboBox

         Case Label

    End Select
Next




But it says that "Is expected" after the second line. Is there any technique to do it?

Regards
SKPaul

Is This A Good Question/Topic? 0
  • +

Replies To: Select Case TypeOf Control Possible?

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Select Case TypeOf Control Possible?

Posted 09 August 2011 - 11:21 PM

It's not possible to compare types in select case but this is pretty close:

        Dim x As Label
        Select Case x.GetType.Name
            Case GetType(Label).Name
                MessageBox.Show("label")
            Case GetType(TextBox).Name
                MessageBox.Show("textbox")
        End Select



Problem is that the above doesn't support polymorphism at all. So when comparing types, I'd use if-elseif.
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,416
  • Joined: 29-May 08

Re: Select Case TypeOf Control Possible?

Posted 10 August 2011 - 03:12 PM

This ability has be suggested to the vb.net language team.

This is closest possible with doing reflection based things.
Selet Case True
  Case x Is TypeOf( Label )
  Case x Is TypeOf( TextBox )
  Case Else
   ' None of the above'
End Case


This post has been edited by AdamSpeight2008: 10 August 2011 - 03:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1