|
-
Dec 29th, 2005, 07:42 PM
#1
Thread Starter
Addicted Member
Array [RESOLVED]
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?
Last edited by SllX; Dec 30th, 2005 at 11:01 PM.
-
Dec 29th, 2005, 07:53 PM
#2
Re: Array
You can use the following sample but I don't see any point in it:
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
NOTE: your control array is assumed to be ZERO based and indexes are all consecutive numbers (say 0 through 17).
-
Dec 29th, 2005, 07:59 PM
#3
Lively Member
Re: Array
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!
-
Dec 29th, 2005, 08:06 PM
#4
Re: Array
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.
-
Dec 29th, 2005, 08:08 PM
#5
Thread Starter
Addicted Member
Re: Array
 Originally Posted by RhinoBull
You can use the following sample but I don't see any point in it:
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
NOTE: your control array is assumed to be ZERO based and indexes are all consecutive numbers (say 0 through 17).
I am confused as to how i recall this information. For example let say i wanted add this array to a listbox
-
Dec 29th, 2005, 08:10 PM
#6
Re: Array
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
-
Dec 29th, 2005, 08:19 PM
#7
Lively Member
Re: Array
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 Well thanks for correcting me, I guess I can learn a lot here on this forum
-
Dec 29th, 2005, 08:20 PM
#8
Thread Starter
Addicted Member
Re: Array
 Originally Posted by RhinoBull
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
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.
-
Dec 29th, 2005, 08:22 PM
#9
Thread Starter
Addicted Member
Re: Array
The only problem i am having is the error about the label control already existing. I dount its possible to change the labelname...
-
Dec 29th, 2005, 08:23 PM
#10
Thread Starter
Addicted Member
Re: Array
Thanks for the tip on the array
-
Dec 29th, 2005, 08:28 PM
#11
Re: 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.
-
Dec 29th, 2005, 08:29 PM
#12
Re: Array
 Originally Posted by SllX
The only problem i am having is the error about the label control already existing. I dount its possible to change the labelname...
No, you cannot change control's name either.
-
Dec 29th, 2005, 08:32 PM
#13
Re: Array
 Originally Posted by gtheman
so you're saying that a dynamic array automatically shifts up the entries if one is being deleted out? ...
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...).
-
Dec 29th, 2005, 08:39 PM
#14
Lively Member
Re: Array
thanks, you're really helping me out
-
Dec 29th, 2005, 08:41 PM
#15
Thread Starter
Addicted Member
Re: Array
 Originally Posted by gtheman
thanks, you're really helping me out 
Who is helping you ?
-
Dec 29th, 2005, 08:51 PM
#16
Lively Member
Re: Array
 Originally Posted by gtheman
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  Well thanks for correcting me, I guess I can learn a lot here on this forum 
 Originally Posted by RhinoBull
@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.
 Originally Posted by RhinoBull
 Originally Posted by gtheman
Originally Posted by gtheman
so you're saying that a dynamic array automatically shifts up the entries if one is being deleted out? ...
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...).
Seems obvious to me , RhinoBull is helping me out...
-
Dec 29th, 2005, 08:53 PM
#17
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
|