Results 1 to 7 of 7

Thread: Control Ojects

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    Unhappy Control Ojects

    Hi All:
    I need some serious help because I am lost!!!!!
    I have a collection. I add a frame to that collectio and attached few objects to the collection. (i.e combobox and textboxes). My goal is to add and remove collection and all the object inside the collection,but it is not workin.
    I am able to add the object to my collection at run time the first time my form is loaded,however when I try to add the object the second time, I get an error. The error is:"There is already a control with the name 'Frame1'. I get this error even though I remove the oject, or at least I think I am. Please can someone help me, before I loose my mind.

    Here is my code:
    Dim colScroll As New Collection
    Private sFrame As String

    If sFrame = "Frame" & CStr(1) Then
    For Num = 1 To colScroll.Count
    colScroll.Remove Num ' remove
    Next
    End If

    sFrame = "Frame" & CStr(1)
    Controls.Add "VB.Frame", sFrame, Me

    'Position the frame and set its properties.
    With Controls(sFrame)
    .Top = 3960
    .Left = 240
    .Height = 1815
    .Width = 5200
    .BorderStyle = 0
    .Visible = True
    .ZOrder (0)
    End With
    ' Maintain a collection of scrollbar values
    colScroll.Add 0, sFrame
    ' Add 3 new controls to the frame.

    'Combobox
    Call Controls.Add("VB.ComboBox", "Combo" & CStr(nPtr), Controls(sFrame))
    Load Combo0(1)
    Set Combo0(1).Container = Controls(sFrame)
    sValue = ""
    With Combo0(1)
    .Visible = True
    .Width = 1580
    End With

    Thanks for everything!!!!!!!!
    Zus

  2. #2

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95
    Thanks for getting back to me.
    I am new to vb. I know how to add a frame and change the index to 0,but not sure how to go about the rest of the code. Can you please give me an example that would show me how to add objects such as comboboxes and text boxes to a frame at run time and unload and reload the object with different values.

    Thanks so much
    Zus

  4. #4

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I remove the oject, or at least I think I am
    Removing the Control from your collection alone is not enough. You must remove (unload) it from the Form as well.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95
    Hi Martin:
    Actually I tried something new and it worked. This is what I did.

    If sFrame = "Frame" & CStr(1) Then
    For i = 1 To Combo0.UBound
    Unload Combo0(i)
    Next
    For i = 2 To Text0.UBound
    Unload Text0(i)
    Next
    For Num = 1 To colScroll.Count ' Remove name from the collection.
    colScroll.Remove Num ' Since collections are reindexed
    Next
    Controls.Remove sFrame
    End If

    Thanks
    Zus

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95
    Thanks all of you for helping me. This is a great thread, I am glad I found this thread. Again thanks very much., all of you.
    Zus

Posting Permissions

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



Click Here to Expand Forum to Full Width