Results 1 to 17 of 17

Thread: Array [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    Resolved 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.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Array

    You can use the following sample but I don't see any point in it:
    VB Code:
    1. Dim arCaptions() As String
    2. Dim i As Integer
    3.  
    4. On Error Resume Next
    5.  
    6. Redim arCaptions(Label1.Ubound)
    7. For i = 0 To UBound(arCaptions)
    8.     arCaptions(i) = Label(i).Caption
    9. Next i
    NOTE: your control array is assumed to be ZERO based and indexes are all consecutive numbers (say 0 through 17).

  3. #3
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Array

    When I'm right the code should look like this:

    add this to the top of the class
    VB Code:
    1. Dim strLabelarray(49) as string

    this should be put into the sub where it's gonna be saved:
    VB Code:
    1. Dim x as integer
    2.  
    3. For x = 0 to 49
    4. strLabelarray(x) = label(x).caption
    5. next x

    When you want to recall the strings in the array back into the labels, this should be the code:
    VB Code:
    1. Dim x as integer
    2.  
    3. For x = 0 to 49
    4. label(x).caption = strLabelarray(x)
    5. 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!

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    Question Re: Array

    Quote Originally Posted by RhinoBull
    You can use the following sample but I don't see any point in it:
    VB Code:
    1. Dim arCaptions() As String
    2. Dim i As Integer
    3.  
    4. On Error Resume Next
    5.  
    6. Redim arCaptions(Label1.Ubound)
    7. For i = 0 To UBound(arCaptions)
    8.     arCaptions(i) = Label(i).Caption
    9. 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

  6. #6

  7. #7
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    Re: Array

    Quote Originally Posted by RhinoBull
    I'm confused as to what you want to do at all now...
    VB Code:
    1. Dim i As Integer
    2.  
    3. For i = 0 To UBound(arCaptions)
    4.     List1.AddItem arCaptions(i)
    5. 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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    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...

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    Re: Array

    Thanks for the tip on the array

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  12. #12

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Array

    Quote 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...).

  14. #14
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Array

    thanks, you're really helping me out

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    129

    Question Re: Array

    Quote Originally Posted by gtheman
    thanks, you're really helping me out

    Who is helping you ?

  16. #16
    Lively Member
    Join Date
    Dec 2005
    Location
    In front of my pc
    Posts
    78

    Re: Array

    Quote 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
    Quote 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.
    Quote Originally Posted by RhinoBull
    Quote 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...

  17. #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
  •  



Click Here to Expand Forum to Full Width