[RESOLVED]Event Load Cannot be found-VBForums
Results 1 to 23 of 23

Thread: [RESOLVED]Event Load Cannot be found

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    [RESOLVED]Event Load Cannot be found

    Guys. I have an issue i introduced a sub called

    Private Sub EU_LEGAL1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Which worked great.

    Then i put another sub in called

    Private Sub EU_LEGAL2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    But this produces a error Event Load Cannot be found

    and this is on the

    Private Sub EU_LEGAL2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    The code is below.

    Any ideas?

    Thanks in advance

    Code:
    Private Sub EU_LEGAL1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
            Dim filter As String = "(&(objectCategory=group)(groupType=2)(|(name=uk*)(name=gn*)(name=mn*)))"
            Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "cn"})
            searcher.Sort.PropertyName = "cn"
            searcher.Sort.Direction = SortDirection.Ascending
            Dim Results As SearchResultCollection = searcher.FindAll
    
            Dim a As New ArrayList
    
            For Each result As SearchResult In Results
                If result.Properties.Contains("distinguishedName") Then
                    Dim item As New DN(result.Properties("cn")(0).ToString, result.Properties("distinguishedName")(0).ToString)
                    a.Add(item)
                End If
            Next
    
            With ListBoxDisplayDL
                .DataSource = a
                .DisplayMember = "Name"
                .ValueMember = "DistinguishedName"
            End With
    
        End Sub
    
    End Class
    
    Public Class DN
        Private _name As String
        Private _distinguishedName As String
    
        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedName() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
    
        'End Class
    
        Private Sub EU_LEGAL2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim entry As New DirectoryEntry("LDAP://OU=Users,OU=Europe,OU=Withers,DC=withers,DC=net") 
            Dim filter As String = "(&(objectCategory=OrganizationalUnit))"
            Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "name"})
            searcher.Sort.PropertyName = "name"
            searcher.Sort.Direction = SortDirection.Ascending
            Dim Results As SearchResultCollection = searcher.FindAll
    
            Dim WithersOU As New ArrayList
    
            For Each result As SearchResult In Results
                If result.Properties.Contains("distinguishedName") Then
                    Dim ItemOU As New DN(result.Properties("name")(0).ToString, result.Properties("distinguishedName")(0).ToString)
                    WithersOU.Add(ItemOU)
                End If
            Next
    
            Dim ListBoxDisplayWithersOU1 As New ListBox
            With ListBoxDisplayWithersOU1
                .DataSource = WithersOU
                .DisplayMember = "Name"
                .ValueMember = "DistinguishedName"
            End With
    
        End Sub
    
    
    
    
        'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '    For Each item As DN In ListBoxDisplayWithersOU.SelectedItems
        '        MsgBox(item.Name & "    " & item.DistinguishedName)
        '    Next
        'End Sub
    End Class
    
    Public Class DNOU
        Private _name As String
        Private _distinguishedName As String
    
        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedName() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
    
    End Class
    Last edited by cjwallace; Jul 25th, 2007 at 07:32 AM.
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  2. #2
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    23,830

    Re: Event Load Cannot be found

    What's the point? One sub is registered to be called when the base raises the Load event. If you were to have a second sub also registered in the same class, you are basically wasting your time, because even if it did work right, it would just be a case of one sub following right after the other sub. Just have the first one call the second, or combine them into one.

    I can't see any reason why having two would necessarily be prevented, but I can think of a couple ways that it might. Still, it's pretty much pointless, so maybe MS just figured that nobody would try to do it.

    What is the objective you were hoping to achieve?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    i feel a little flamed here! Please tell me if you know a better way. I have two list box's on my form. one of the list box's query AD for all the Exchange Distribution lists and pops them all in the List Box. The second list box does the same only it displays all the OU's

    I am still new to vb.net so looking for help.
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  4. #4
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    331

    Re: Event Load Cannot be found

    Just like Shaggy said, Place the second load event code in a seperate Sub and call it from the first load event.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Ok, sorry please explain as the second load is already in a seperate sub?
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  6. #6
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    331

    Re: Event Load Cannot be found

    This is just a copy/paste of your original code. All I did is removed the Mybase.Load handle off of your second sub and called it from the first instead. Not sure if this will work because the code you pasted doesn't make sense to me. Being that I see alot of "End Class" lines.

    vb Code:
    1. Private Sub EU_LEGAL1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
    4.         Dim filter As String = "(&(objectCategory=group)(groupType=2)(|(name=uk*)(name=gn*)(name=mn*)))"
    5.         Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "cn"})
    6.         searcher.Sort.PropertyName = "cn"
    7.         searcher.Sort.Direction = SortDirection.Ascending
    8.         Dim Results As SearchResultCollection = searcher.FindAll
    9.  
    10.         Dim a As New ArrayList
    11.  
    12.         For Each result As SearchResult In Results
    13.             If result.Properties.Contains("distinguishedName") Then
    14.                 Dim item As New DN(result.Properties("cn")(0).ToString, result.Properties("distinguishedName")(0).ToString)
    15.                 a.Add(item)
    16.             End If
    17.         Next
    18.  
    19.         With ListBoxDisplayDL
    20.             .DataSource = a
    21.             .DisplayMember = "Name"
    22.             .ValueMember = "DistinguishedName"
    23.         End With
    24.         EU_LEGAL2_Load() 'This line here will call the second sub
    25.     End Sub
    26.  
    27. End Class
    28.  
    29. Public Class DN
    30.     Private _name As String
    31.     Private _distinguishedName As String
    32.  
    33.     Public Property Name() As String
    34.         Get
    35.             Return _name
    36.         End Get
    37.         Set(ByVal Value As String)
    38.             _name = Value
    39.         End Set
    40.     End Property
    41.  
    42.     Public Property DistinguishedName() As String
    43.         Get
    44.             Return _distinguishedName
    45.         End Get
    46.         Set(ByVal Value As String)
    47.             _distinguishedName = Value
    48.         End Set
    49.     End Property
    50.  
    51.     Public Sub New(ByVal n As String, ByVal dn As String)
    52.         _name = n
    53.         _distinguishedName = dn
    54.     End Sub
    55.  
    56.     'End Class
    57.  
    58.     Private Sub EU_LEGAL2_Load()
    59.         Dim entry As New DirectoryEntry("LDAP://OU=Users,OU=Europe,OU=Withers,DC=withers,DC=net")
    60.         Dim filter As String = "(&(objectCategory=OrganizationalUnit))"
    61.         Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "name"})
    62.         searcher.Sort.PropertyName = "name"
    63.         searcher.Sort.Direction = SortDirection.Ascending
    64.         Dim Results As SearchResultCollection = searcher.FindAll
    65.  
    66.         Dim WithersOU As New ArrayList
    67.  
    68.         For Each result As SearchResult In Results
    69.             If result.Properties.Contains("distinguishedName") Then
    70.                 Dim ItemOU As New DN(result.Properties("name")(0).ToString, result.Properties("distinguishedName")(0).ToString)
    71.                 WithersOU.Add(ItemOU)
    72.             End If
    73.         Next
    74.  
    75.         Dim ListBoxDisplayWithersOU1 As New ListBox
    76.         With ListBoxDisplayWithersOU1
    77.             .DataSource = WithersOU
    78.             .DisplayMember = "Name"
    79.             .ValueMember = "DistinguishedName"
    80.         End With
    81.  
    82.     End Sub
    83.  
    84.  
    85.  
    86.  
    87.     'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    88.     '    For Each item As DN In ListBoxDisplayWithersOU.SelectedItems
    89.     '        MsgBox(item.Name & "    " & item.DistinguishedName)
    90.     '    Next
    91.     'End Sub
    92. End Class
    93.  
    94. Public Class DNOU
    95.     Private _name As String
    96.     Private _distinguishedName As String
    97.  
    98.     Public Property Name() As String
    99.         Get
    100.             Return _name
    101.         End Get
    102.         Set(ByVal Value As String)
    103.             _name = Value
    104.         End Set
    105.     End Property
    106.  
    107.     Public Property DistinguishedName() As String
    108.         Get
    109.             Return _distinguishedName
    110.         End Get
    111.         Set(ByVal Value As String)
    112.             _distinguishedName = Value
    113.         End Set
    114.     End Property
    115.  
    116.     Public Sub New(ByVal n As String, ByVal dn As String)
    117.         _name = n
    118.         _distinguishedName = dn
    119.     End Sub
    120.  
    121. End Class

  7. #7
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    23,830

    Re: Event Load Cannot be found

    Quote Originally Posted by cjwallace
    i feel a little flamed here! Please tell me if you know a better way. I have two list box's on my form. one of the list box's query AD for all the Exchange Distribution lists and pops them all in the List Box. The second list box does the same only it displays all the OU's

    I am still new to vb.net so looking for help.

    I certainly meant no flaming. There were a couple of possible things that I thought you might have been intending with that. I'm actually a little surprised that it didn't work the way you have it, though it is irregular. Frankly, you only find really neat things when you try the irregular.

    In fact, upon looking at the code again, I think I misread it the first time. You appear to have three different classes, where I first thought you had one. The first sub looks like it might have been taken directly from a form, while the second sub looks like it is in a separate class. Is that correct? If so, then you really SHOULD be able to do this, and are very close, but I think this time I'll keep my foot out of my mouth until you tell me whether I got that part right.
    My usual boring signature: Nothing

  8. #8
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    23,830

    Re: Event Load Cannot be found

    Quote Originally Posted by zalez
    This is just a copy/paste of your original code. All I did is removed the Mybase.Load handle off of your second sub and called it from the first instead. Not sure if this will work because the code you pasted doesn't make sense to me. Being that I see alot of "End Class" lines.

    vb Code:
    1. Private Sub EU_LEGAL1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
    4.         Dim filter As String = "(&(objectCategory=group)(groupType=2)(|(name=uk*)(name=gn*)(name=mn*)))"
    5.         Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "cn"})
    6.         searcher.Sort.PropertyName = "cn"
    7.         searcher.Sort.Direction = SortDirection.Ascending
    8.         Dim Results As SearchResultCollection = searcher.FindAll
    9.  
    10.         Dim a As New ArrayList
    11.  
    12.         For Each result As SearchResult In Results
    13.             If result.Properties.Contains("distinguishedName") Then
    14.                 Dim item As New DN(result.Properties("cn")(0).ToString, result.Properties("distinguishedName")(0).ToString)
    15.                 a.Add(item)
    16.             End If
    17.         Next
    18.  
    19.         With ListBoxDisplayDL
    20.             .DataSource = a
    21.             .DisplayMember = "Name"
    22.             .ValueMember = "DistinguishedName"
    23.         End With
    24.         EU_LEGAL2_Load() 'This line here will call the second sub
    25.     End Sub
    26.  
    27. End Class
    28.  
    29. Public Class DN
    30.     Private _name As String
    31.     Private _distinguishedName As String
    32.  
    33.     Public Property Name() As String
    34.         Get
    35.             Return _name
    36.         End Get
    37.         Set(ByVal Value As String)
    38.             _name = Value
    39.         End Set
    40.     End Property
    41.  
    42.     Public Property DistinguishedName() As String
    43.         Get
    44.             Return _distinguishedName
    45.         End Get
    46.         Set(ByVal Value As String)
    47.             _distinguishedName = Value
    48.         End Set
    49.     End Property
    50.  
    51.     Public Sub New(ByVal n As String, ByVal dn As String)
    52.         _name = n
    53.         _distinguishedName = dn
    54.     End Sub
    55.  
    56.     'End Class
    57.  
    58.     Private Sub EU_LEGAL2_Load()
    59.         Dim entry As New DirectoryEntry("LDAP://OU=Users,OU=Europe,OU=Withers,DC=withers,DC=net")
    60.         Dim filter As String = "(&(objectCategory=OrganizationalUnit))"
    61.         Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "name"})
    62.         searcher.Sort.PropertyName = "name"
    63.         searcher.Sort.Direction = SortDirection.Ascending
    64.         Dim Results As SearchResultCollection = searcher.FindAll
    65.  
    66.         Dim WithersOU As New ArrayList
    67.  
    68.         For Each result As SearchResult In Results
    69.             If result.Properties.Contains("distinguishedName") Then
    70.                 Dim ItemOU As New DN(result.Properties("name")(0).ToString, result.Properties("distinguishedName")(0).ToString)
    71.                 WithersOU.Add(ItemOU)
    72.             End If
    73.         Next
    74.  
    75.         Dim ListBoxDisplayWithersOU1 As New ListBox
    76.         With ListBoxDisplayWithersOU1
    77.             .DataSource = WithersOU
    78.             .DisplayMember = "Name"
    79.             .ValueMember = "DistinguishedName"
    80.         End With
    81.  
    82.     End Sub
    83.  
    84.  
    85.  
    86.  
    87.     'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    88.     '    For Each item As DN In ListBoxDisplayWithersOU.SelectedItems
    89.     '        MsgBox(item.Name & "    " & item.DistinguishedName)
    90.     '    Next
    91.     'End Sub
    92. End Class
    93.  
    94. Public Class DNOU
    95.     Private _name As String
    96.     Private _distinguishedName As String
    97.  
    98.     Public Property Name() As String
    99.         Get
    100.             Return _name
    101.         End Get
    102.         Set(ByVal Value As String)
    103.             _name = Value
    104.         End Set
    105.     End Property
    106.  
    107.     Public Property DistinguishedName() As String
    108.         Get
    109.             Return _distinguishedName
    110.         End Get
    111.         Set(ByVal Value As String)
    112.             _distinguishedName = Value
    113.         End Set
    114.     End Property
    115.  
    116.     Public Sub New(ByVal n As String, ByVal dn As String)
    117.         _name = n
    118.         _distinguishedName = dn
    119.     End Sub
    120.  
    121. End Class
    Careful, since DN is a separate class, you can't simply call a method of a different class in that fashion. I think we need a little more clarification here.
    My usual boring signature: Nothing

  9. #9
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    331

    Re: Event Load Cannot be found

    You are right Shaggy, I seen all of the End Class lines but missed the begin lines. That is why I was confused. Cj, is this all of the code you have?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Zalez. I did what you suggested and it removed the error and the form opens. But it is not displaying all the OU's in the list box.

    When
    Private Sub EU_LEGAL1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    is used on its own it works perfect or if #
    Private Sub EU_LEGAL2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    is used on its own all is ok......odd

    If you can think of a better way of doing please let me know

    Thanks to everyone who is trying to hep me.
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Quote Originally Posted by zalez
    You are right Shaggy, I seen all of the End Class lines but missed the begin lines. That is why I was confused. Cj, is this all of the code you have?

    No there is alot of code above this code that i am having a few problems with. I can post the whole code if you like. It make take sometime as i need to stip usernames and passwords out of it.

    Craig
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  12. #12
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    23,830

    Re: Event Load Cannot be found

    Well, how about just this:

    1) It appears that the first sub is in a form. True?

    2) It appears that the second sub is in a class. Is the class defined in the form, or in a different module?

    If 1 is true, then here is where the original problem came from:

    When an event is raised, all that happens is that the class that provides the event goes to a (pretty much hidden) list of functions that it is supposed to call. All classes that want to deal with that event have to tell the class that provides the event "I want to know about your events, and here is a sub for you to call when the event happens". You do this by declaring an instance of the provider class using WithEvents:

    private WithEvents someClass as someTypeOfClass

    Or by using an AddHandler function (which I can't prototype for you off the top of my head, but that's oke for now).

    Either of those methods will just tell the event provider that you want to deal with any events they raise. You have to handle the events using the Handles phrase that you already know, and the sub has to have the same signature as the event (same number and type of arguments).

    This may not help your situation. To get the Handles portion of the second sub to work, you would have to have that class register with the event provider, which appears to be the base class of the form that has the first sub. I have never tried to grab events from a form like that, though adding something like this to the DN class should work:

    Private WithEvents myForm as <FormTypeNameHere>

    However, if question 2 is true, and DN is defined in the form, then I think there is an easier way rather than handling the events.
    My usual boring signature: Nothing

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Ok. Its late and my head hurts. I will pick this up again tomorrow and see what i can do.

    In answer to your question option 1 is true.

    Thanks to everyone who has tried to help tonight , as said i will pick this up again tomorrow.

    Bye for now :-)
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Hi Guys. Ok so i am picking this back up again.

    What i have done is just take the code i need to get working and put it in a new project and a new form. This might hopefully make it easier for people to work out.

    Ok so with the code if you put this in a new form and create to list box's called

    ListBoxDisplayWithersDL

    and

    ListBoxDisplayWithersOU

    You will see the error and hopefully you might spot the problem

    Please see the most up to date code, i have cleaned it up a bit but the same problem still stands.

    Thanks to anyone who can help me fix this.

    Thanks again.



    Code:
    Imports System.DirectoryServices
    
    Public Class Form1
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
            Dim filter As String = "(&(objectCategory=group)(groupType=2)(|(name=eu*)(name=uk*)(name=gn*)(name=mn*)))"
            Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "cn"})
            searcher.Sort.PropertyName = "cn"
            searcher.Sort.Direction = SortDirection.Ascending
            Dim Results As SearchResultCollection = searcher.FindAll
    
            Dim WithersDLArray As New ArrayList
    
            For Each result As SearchResult In Results
                If result.Properties.Contains("distinguishedName") Then
                    Dim item As New WithersDLDN(result.Properties("cn")(0).ToString, result.Properties("distinguishedName")(0).ToString)
                    WithersDLArray.Add(item)
                End If
            Next
    
            With ListBoxDisplayWithersDL
                .DataSource = WithersDLArray
                .DisplayMember = "NameDL"
                .ValueMember = "DistinguishedNameDL"
            End With
    
        End Sub
    
    End Class
    
    Public Class WithersDLDN
        Private _name As String
        Private _distinguishedName As String
    
        Public Property NameDL() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedNameDL() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
        'End Class
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim entry As New DirectoryEntry("LDAP://DC=Withers, DC=Net")
            Dim filter As String = "(&(objectCategory=OrganizationalUnit))"
            Dim searcher As New DirectorySearcher(entry, filter, New String() {"distinguishedName", "name"})
            searcher.Sort.PropertyName = "name"
            searcher.Sort.Direction = SortDirection.Ascending
            Dim Results As SearchResultCollection = searcher.FindAll
    
            Dim WithersOUArray As New ArrayList
    
            For Each result As SearchResult In Results
                If result.Properties.Contains("distinguishedName") Then
                    Dim item As New WithersOUDN(result.Properties("name")(0).ToString, result.Properties("distinguishedName")(0).ToString)
                    WithersOUArray.Add(item)
                End If
            Next
    
            Dim ListBoxDisplayWithersOU As New ListBox
    
            With ListBoxDisplayWithersOU
                .DataSource = WithersOUArray
                .DisplayMember = "NameOU"
                .ValueMember = "DistinguishedNameOU"
            End With
    
        End Sub
    
        'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '    For Each item As DN In ListBoxDisplayWithersDL.SelectedItems
        '        MsgBox(item.Name & "    " & item.DistinguishedName)
        '    Next
        'End Sub
    End Class
    
    Public Class WithersOUDN
        Private _name As String
        Private _distinguishedName As String
    
        Public Property NameOU() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedNameOU() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
    End Class
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  15. #15
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    331

    Re: Event Load Cannot be found

    ok back to the original suggestion. You can't do the following because there are no events in your WithersDLDN
    class.

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Change it to:
    Code:
    Private Sub Form1_Load()
    And then also the next line is why it isn't showing up right. Because you are making a new listbox instead of appending the one you already have.

    Code:
    Dim ListBoxDisplayWithersOU As New ListBox

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Quote Originally Posted by zalez
    ok back to the original suggestion. You can't do the following because there are no events in your WithersDLDN
    class.

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Change it to:
    Code:
    Private Sub Form1_Load()
    And then also the next line is why it isn't showing up right. Because you are making a new listbox instead of appending the one you already have.

    Code:
    Dim ListBoxDisplayWithersOU As New ListBox
    Hi mate. If i do as you suggested

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Change it to:
    Code:
    Private Sub Form1_Load()
    Then it gets rid of my Event Load Cannont be found message but when i run the form nothing is displayed in my list boxs which is why i think i needed the line

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Also i see what your saying about the

    Code:
    Dim ListBoxDisplayWithersOU As New ListBox
    [/QUOTE]

    So i just have set as

    Code:
    Dim ListBoxDisplayWithersOU As ListBox
    [/QUOTE]

    It is asking for it to be dim'ed as something.

    Any ideas as to whats going on? I feel we are close to getting a result.

    Thanks again
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  17. #17
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    331

    Re: Event Load Cannot be found

    Ok my last suggestion for the listbox is don't dim it, just reference it using
    Code:
    Form1.ListBoxDisplayWithersOU
    Unfortunately I don't have AD to even help you test so I am out of suggestions

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    Hi mate

    If i put that in my code i get

    Property access must assign to the property or use its value.

    Anyway thanks very much for all your help that you have given to me. :-)

    Ok can anyone else try and help me fix this. i feel i am almost there.
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    bump
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    I have been playing around with all sorts of ways of doing this. If each sub is run on its own then they work. I cant get this to display data in both listboxs when the form is loaded.

    Please if anyone can help , i am at my wits end trying to solve this.

    Thanks in advance
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: Event Load Cannot be found

    bump
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    215

    Re: [RESOLVED]Event Load Cannot be found

    Hi guys. ok i have finally worked it out.

    What i did was merge the two subs into one and now when the form loads it displays data in both list boxs. .....YAY

    See below to what i did


    Thanks to everyone who tried to help

    Code:
    Dim DLentry As New DirectoryEntry("LDAP://DC=withers,DC=net")
            Dim DLfilter As String = "(&(objectCategory=group)(groupType=2)(|(name=eu*)(name=uk*)(name=gn*)(name=mn*)))"
            Dim DLsearcher As New DirectorySearcher(DLentry, DLfilter, New String() {"distinguishedName", "cn"})
            DLsearcher.Sort.PropertyName = "cn"
            DLsearcher.Sort.Direction = SortDirection.Ascending
            Dim DLResults As SearchResultCollection = DLsearcher.FindAll
    
            Dim WithersDLArray As New ArrayList
    
            For Each DLresult As SearchResult In DLResults
                If DLresult.Properties.Contains("distinguishedName") Then
                    Dim DLitem As New WithersDLDN(DLresult.Properties("cn")(0).ToString, DLresult.Properties("distinguishedName")(0).ToString)
                    WithersDLArray.Add(DLitem)
                End If
            Next
    
            With ListBoxDisplayWithersDL
                .DataSource = WithersDLArray
                .DisplayMember = "NameDL"
                .ValueMember = "DistinguishedNameDL"
            End With
    
            ' Withers OU Query
    
            Dim OUentry As New DirectoryEntry("LDAP://OU=London,OU=Users,OU=Europe,OU=Withers,DC=withers,DC=net")
            Dim OUfilter As String = "(&(objectCategory=OrganizationalUnit))"
            Dim OUsearcher As New DirectorySearcher(OUentry, OUfilter, New String() {"distinguishedName", "name"})
            OUsearcher.Sort.PropertyName = "name"
            OUsearcher.Sort.Direction = SortDirection.Ascending
            Dim OUResults As SearchResultCollection = OUsearcher.FindAll
    
            Dim WithersOUArray As New ArrayList
    
            For Each OUresult As SearchResult In OUResults
                If OUresult.Properties.Contains("distinguishedName") Then
                    Dim OUitem As New WithersOUDN(OUresult.Properties("name")(0).ToString, OUresult.Properties("distinguishedName")(0).ToString)
                    WithersOUArray.Add(OUitem)
                End If
            Next
    
            With ListBoxDisplayWithersOU
                .DataSource = WithersOUArray
                .DisplayMember = "NameOU"
                .ValueMember = "DistinguishedNameOU"
            End With
    
    
        End Sub
    The updated code

    Code:
    Imports System.DirectoryServices
    
    Public Class Form1
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
            ' Withers DL Query
    
            Dim DLentry As New DirectoryEntry("LDAP://DC=withers,DC=net")
            Dim DLfilter As String = "(&(objectCategory=group)(groupType=2)(|(name=eu*)(name=uk*)(name=gn*)(name=mn*)))"
            Dim DLsearcher As New DirectorySearcher(DLentry, DLfilter, New String() {"distinguishedName", "cn"})
            DLsearcher.Sort.PropertyName = "cn"
            DLsearcher.Sort.Direction = SortDirection.Ascending
            Dim DLResults As SearchResultCollection = DLsearcher.FindAll
    
            Dim WithersDLArray As New ArrayList
    
            For Each DLresult As SearchResult In DLResults
                If DLresult.Properties.Contains("distinguishedName") Then
                    Dim DLitem As New WithersDLDN(DLresult.Properties("cn")(0).ToString, DLresult.Properties("distinguishedName")(0).ToString)
                    WithersDLArray.Add(DLitem)
                End If
            Next
    
            With ListBoxDisplayWithersDL
                .DataSource = WithersDLArray
                .DisplayMember = "NameDL"
                .ValueMember = "DistinguishedNameDL"
            End With
    
            ' Withers OU Query
    
            Dim OUentry As New DirectoryEntry("LDAP://OU=London,OU=Users,OU=Europe,OU=Withers,DC=withers,DC=net")
            Dim OUfilter As String = "(&(objectCategory=OrganizationalUnit))"
            Dim OUsearcher As New DirectorySearcher(OUentry, OUfilter, New String() {"distinguishedName", "name"})
            OUsearcher.Sort.PropertyName = "name"
            OUsearcher.Sort.Direction = SortDirection.Ascending
            Dim OUResults As SearchResultCollection = OUsearcher.FindAll
    
            Dim WithersOUArray As New ArrayList
    
            For Each OUresult As SearchResult In OUResults
                If OUresult.Properties.Contains("distinguishedName") Then
                    Dim OUitem As New WithersOUDN(OUresult.Properties("name")(0).ToString, OUresult.Properties("distinguishedName")(0).ToString)
                    WithersOUArray.Add(OUitem)
                End If
            Next
    
            With ListBoxDisplayWithersOU
                .DataSource = WithersOUArray
                .DisplayMember = "NameOU"
                .ValueMember = "DistinguishedNameOU"
            End With
    
    
        End Sub
    
    
    End Class
    
    ' This Section is part of the Withers DL Section
    
    Public Class WithersDLDN
        Private _name As String
        Private _distinguishedName As String
    
        Public Property NameDL() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedNameDL() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
    
    End Class
    
    
    ' This section is part of the Withers OU Query
    
    Public Class WithersOUDN
        Private _name As String
        Private _distinguishedName As String
    
        Public Property NameOU() As String
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
            End Set
        End Property
    
        Public Property DistinguishedNameOU() As String
            Get
                Return _distinguishedName
            End Get
            Set(ByVal Value As String)
                _distinguishedName = Value
            End Set
        End Property
    
        Public Sub New(ByVal n As String, ByVal dn As String)
            _name = n
            _distinguishedName = dn
        End Sub
    End Class
    Thanks

    Craig Wallace

    Active Directory Administrator \ Designer

    SMS 2003 Administrator

    Everything else Networks

  23. #23
    Junior Member
    Join Date
    Jun 2012
    Posts
    25

    Re: [RESOLVED]Event Load Cannot be found

    ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.