If i have 50 labels in array
label(0) to label(49)
all with different caption. How would i put the caption of each label in an array to recall the string at a later time?
Printable View
If i have 50 labels in array
label(0) to label(49)
all with different caption. How would i put the caption of each label in an array to recall the string at a later time?
You can use the following sample but I don't see any point in it:
NOTE: your control array is assumed to be ZERO based and indexes are all consecutive numbers (say 0 through 17).VB Code:
Dim arCaptions() As String Dim i As Integer On Error Resume Next Redim arCaptions(Label1.Ubound) For i = 0 To UBound(arCaptions) arCaptions(i) = Label(i).Caption Next i
When I'm right the code should look like this:
add this to the top of the class
VB Code:
Dim strLabelarray(49) as string
this should be put into the sub where it's gonna be saved:
VB Code:
Dim x as integer For x = 0 to 49 strLabelarray(x) = label(x).caption next x
When you want to recall the strings in the array back into the labels, this should be the code:
VB Code:
Dim x as integer For x = 0 to 49 label(x).caption = strLabelarray(x) next x
hope this helped you, I'm not that good at vb6 so I hope this will work ;)
EDIT: Didn't see that someone else posted a solution earlier... sorry!
What if he decides to add or remove few labels of that control array?
Using your sample he will need to change code so instead if you'd use dynamic array (demonstrated in my sample) you won't to change anything at all.
Quote:
Originally Posted by RhinoBull
I am confused as to how i recall this information. For example let say i wanted add this array to a listbox
I'm confused as to what you want to do at all now... :)
VB Code:
Dim i As Integer For i = 0 To UBound(arCaptions) List1.AddItem arCaptions(i) Next i
so you're saying that a dynamic array automatically shifts up the entries if one is being deleted out? If that is true, can you give me a small sample which shows how to take out an entry in the middle of the array because I've been looking foor that for quite some time :rolleyes: Well thanks for correcting me, I guess I can learn a lot here on this forum :cool:
Quote:
Originally Posted by RhinoBull
OK this is exctly what i am doing. I have created an array of labels at runtime to display records from a database and stack them like a list. I made it so i can delete a label if i choose based on the index of the label. When i delete a label i want to be able to arrange the labels in a orderly fation again snd emoving the gap where the deleted label once used to be.. If possible i would then like to reset the index of each labels so i can continue to add more labels when i want without getting errors that the label already exists.
I didnt know any other way to to this except add the label captions to an array and then remove all labels then reload the labels with the information from the array . I hope this is more clear.
The only problem i am having is the error about the label control already existing. I dount its possible to change the labelname...
Thanks for the tip on the array :)
@gtheman:
You cannot "take out an entry in the middle of the array" - you'd have to rebuild your array. You may however use Collection instead that exposes Add/Remove methods.
@SllX:
you cannot reindex control array - if you have to do that then you will basically need to unload all loaded controls (except original with index = 0) and then reload them again (as many as you need) - not a pretty way to handle it.
No, you cannot change control's name either.Quote:
Originally Posted by SllX
Not exactly, dynamic (in this case) means that you may redim array as many times as you need to and also (if necessary) preserve its values (Redim Preserve...).Quote:
Originally Posted by gtheman
thanks, you're really helping me out :)
Quote:
Originally Posted by gtheman
Who is helping you ?
Quote:
Originally Posted by gtheman
Quote:
Originally Posted by RhinoBull
Seems obvious to me :rolleyes: , RhinoBull is helping me out...Quote:
Originally Posted by RhinoBull
Easy boys ... we are all helping each other. ;) :wave: :afrog: