DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: obj.putex with VB.NET?

  1. #1
    Join Date
    Oct 2006

    obj.putex with VB.NET?

    Hi again

    I am trying to set multi-value items in the "otherhomePhone" field of an Active Directory contact but am unable to do so in VB.NET 2005 (Framework 2)

    Here is the original VBSCRIPT which works perfectly but I keep getting an error in .NET as the 'Array' function doesn't exist in this form.

    Dim x As IADs
    On Error GoTo Cleanup
    Set x = GetObject("LDAP://CN=JeffSmith,CN=Users,DC=Fabrikam,DC=com")
    ' Assume the otherHomePhone has the values
    ' 425-707-9790, 425-707-9791
    ' Adding a value
    x.PutEx ADS_PROPERTY_APPEND, "otherhomePhone", Array("425-707-9792")  
    x.SetInfo              ' Now the values are 425-707-9790,425-707-9791,425-707-9792. 
    deleting two values
    x.PutEx ADS_PROPERTY_DELETE, "otherHomePhone", Array("425-707-9790", "425-707-9791")
    x.SetInfo              ' Now the values are 425-707-9792.
    ' Changing the remaining value
    x.PutEx ADS_PROPERTY_UPDATE, "otherHomePhone", Array("425-707-9793", "425-707-9794")
    x.SetInfo              ' Now the values are 425-707-9793,425-707-9794.
    ' Deleting the value
    x.PutEx ADS_PROPERTY_CLEAR, "otherHomePhone",  vbNullString
    x.SetInfo              ' Now the property has no value.
        If(Err.Number<>0) Then
            MsgBox("An error has occurred. " & Err.Number)
        End If
        Set x = Nothing
    I am currently working on the first item (adding a phone number) and have tried declaring a system.array object and setting the array elements one-by-one but this fails with a "object varable or with block variable not set" error. Here is that code portion:

              Dim myArray As System.Array
              myArray(0) = "Hello"
              myArray(1) = "JF"
              myArray(2) = "There!"
              ' Adding a value
              x.PutEx(ADS_PROPERTY_APPEND, "otherhomePhone", myArray)
    Please can anyone help - I've been googling this for hours and can't find a simple way of doing this. Many paths lead to IADs but this is also fairly poorly documented.

    Many thanks for your help


  2. #2
    Join Date
    Nov 2003
    Portland, OR
    In .NET, declaring an array variable does not actually create space for any elements. You must either specify the upper bound in the Dim statement or use an initializer to populate the array. Try this:
    Dim myArray() As String = {"Hello", "JF", "There!"}
    ' The above is shorthand for:
    ' Dim myArray(2) As String
    ' myArray(0) = "Hello"
    ' myArray(1) = "JF"
    ' myArray(2) = "There!"
    ' Adding a value
    x.PutEx(ADS_PROPERTY_APPEND, "otherhomePhone", myArray)
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Oct 2006
    Thanks again Phil

    That's sorted the array declaration out but I still get an "Unspecified Error (ErrorCode=-2147467259)" when the .PUTEX function runs.

    If I run the original vbscript, it works perfectly. I have even cut and pasted the LDAP declaration from the script to my app to avoid typo's - it *should* be working!!

    Also:- this works okay>>
    ' Deleting the value
    x.PutEx ADS_PROPERTY_CLEAR, "otherHomePhone",  vbNullString
    x.SetInfo              ' Now the property has no value.
    but anything that reference the Array function DOES NOT. I can only assume that the VB.NET array isn't the same as the vb/vbscript Array function - is this possible?

    Any more ideas? I can see nothing wrong - not that I'm an expert!!..

    Last edited by NoahPhence; 11-23-2006 at 03:56 PM.

  4. #4
    Join Date
    Oct 2006
    Okay don't ask how but I think I've finally worked it out. This DOES appear to work correctly .. (No - Don't laugh!)

        Dim objGroup
        Dim members(): ReDim members(1)
        objGroup = GetObject(LDAP://CN=JeffSmith,CN=Users,DC=Fabrikam,DC=com"))
        members(0) = "hello"
        members(1) = "There"
        objGroup.PutEx(ADS_PROPERTY_APPEND, "otherHomePhone", members)
    Maybe the Redim statement does something peculiar. It just won't work without it!

    Thanks for your help ..

    Last edited by NoahPhence; 11-23-2006 at 06:01 PM.

Similar Threads

  1. Will VB.NET be more stable than VB6?
    By Jason in forum .NET
    Replies: 125
    Last Post: 10-05-2002, 04:34 PM
  2. Is VB.Net difficult or not - OR - How difficult?
    By Michael Culley in forum .NET
    Replies: 6
    Last Post: 06-19-2002, 09:11 AM
  3. array declarations in VB.NET
    By Bill McCarthy in forum .NET
    Replies: 14
    Last Post: 04-10-2001, 05:03 AM
  4. Is VB.Not still a BEGINNERS' language?
    By Mark Burns in forum .NET
    Replies: 164
    Last Post: 03-13-2001, 01:43 PM
  5. VB.NET: 3 points of view
    By David Kroll in forum .NET
    Replies: 33
    Last Post: 02-13-2001, 11:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center