Jump to content

Recommended Posts

Posted

Dim c As Control
For Each c In Me.Controls
If c.??? = FileListBox Then
   If c.ListCount > 0 Then
       MsgBox "pending files"
   End If
End If
Next

hey there,

i was wondering how we can check the type of the control


Posted (edited)

For VB6

Dim c As Object
 For Each c In Me.Controls
    If TypeName(c) = "FileListBox" Then
       If c.ListCount > 0 Then
          MsgBox ("pending files")
       End If
    End If
 Nextt

For VB.NET (no filelistbox in .net, so I assume you are using VB6?)

Dim c As Object
For Each c In Me.Controls
  If TypeOf (c) Is ListBox Then
     If c.items.count > 0 Then
        MsgBox("pending files")
     End If
  End If
Next

Edited by dman
Posted

Another solution (faster if many controls) :

Dim c As FileListBox
For Each c In Me.Controls
 If c.ListCount > 0 Then
     MsgBox "pending files"
 End If
Next

bye

Posted (edited)

thanks dman, i guess this should do it, i'll try it tomorrow at work.

delprat that wouldn't work, since not all controls have ListCount so it would be an invalid property <-- EDIT: errm nevermind that, didn't pay attention to Dim c as FileListBox it's worth a try thanks anyways

Edited by saprouzy
Posted

Delprat's way is better if you are only checking for one type of control, like the filelistbox. If you are processing all of the controls then the generic "Dim as object" is more versitile.

Posted

delprat's way didn't work ,am getting type mismatch when the c is assigned a control that isn't a filelistbox during the for loop.

am sticking to dman's way.

thanks both :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...