|
-
May 14th, 2004, 02:31 PM
#1
Thread Starter
Lively Member
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!!!!!!!!
-
May 14th, 2004, 02:54 PM
#2
Instead of trying to create Frame1, add one to the form with Index = 0 at design time. You can keep it invisible until needed if you want to. You can then add and remove them with Load/Unload.
-
May 14th, 2004, 03:05 PM
#3
Thread Starter
Lively Member
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
-
May 14th, 2004, 03:24 PM
#4
Sure, but first please explain more about what you want to do. Will there be more than one frame visible at the same time on the form? Will the contents of a frame always be the same? Etc.
-
May 14th, 2004, 03:42 PM
#5
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.
-
May 14th, 2004, 03:47 PM
#6
Thread Starter
Lively Member
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
-
May 14th, 2004, 03:49 PM
#7
Thread Starter
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|