Results 1 to 15 of 15

Thread: Label Arrays.......Moving Text?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118

    Label Arrays.......Moving Text?

    Just wondering if its possible to move text from an array of labels
    to another array of labels in a certain order.?
    for example, this is what i somehow want to do:

    Label1(0).Caption = Label2(0).Caption
    but when i try to put this line in as well:
    Label1(1).Caption = Label2(0).Caption
    only the 2nd line works, does this make sense, and if so how do i do it properly?

  2. #2
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    It would be quicker if you used loops somehow:

    Code:
    For i = 0 to (Label1.Count - 1)
       Label1(i).Caption = Label2(0).Caption
    Next i

    What you have written will set the caption of both Label1(0) and Label1(1) to that which is in Label2(0).Caption property.

    Is that what you want to happen?
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    No, not really, what I want to do is to be able to click on -
    Label1(0).Caption and move its contents to Label2(0).Caption
    or then to be able to click on-
    Label1(1).Caption and move its contents to Label2(0).Caption as well, and so on. Both Label1 and Label2 are Arrays.

  4. #4
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    You should change the assignment order

    Label2(0).Caption=Label1(0).Caption
    Josep Mª

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    Ta joijo,
    But if I type this

    Private Sub Label1_Click(Index As Integer)

    Label2(0).Caption=Label1(0).Caption
    Label2(0).Caption=Label1(1).Caption

    End Sub

    Even if I click on Label1(0) only the contents of Label1(1) is written into Label2(0)

  6. #6
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    Label2(0).Caption=Label1(index).Caption
    Josep Mª

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    Excellent, Ta once again joijo,
    Just 1 more problem, is there a way to determine where the
    text is going, because Label2 is an array also e.g:

    Label2(1).Caption = Label1(1).(Index).Caption

  8. #8
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    For example you can send the text to theitem of label2 array with the same index as the label clicked

    Label2(index).Caption=Label1(index).Caption
    Josep Mª

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    What do I do if I want to send it to a different index?

  10. #10
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    Put the label number wher you want to send it instead of index.

    For example if you want to send in order to the array label
    VB Code:
    1. Label2(count).Caption=Label1(index).Caption
    2. count=count+1

    First time you click the label the text will be sent to Label2(0), second time to Label2(1) and so on.

    This is only an example, now you must make your code according what you want to do
    Josep Mª

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    I must be doing something wrong, i tried-

    Label2(count).Caption=Label1(index).Caption
    count=count+1

    But an error message came up saying-
    Cant assign to read only property
    and count is highlighted.

    Maybe im not explaining myself properly, I have 2 sets of arrays

    Label1(0), Label1(1), Label1(2),Label1(3), Label1(4)...etc.. and
    Label2(0), Label2(1), Label2(2),Label2(3), Label2(4)...etc..

    So.. how do I move text from Label1(0) and Label1(1) into
    Label2(0)
    Then I want to move text from Label1(2) and Label1(3) into
    Label2 (1)

    Is this possible....Please Help me... Ta

  12. #12
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    So.. how do I move text from Label1(0) and Label1(1) into
    Label2(0)
    Then I want to move text from Label1(2) and Label1(3) into
    Label2 (1)


    Label2(0).Caption = Label1(0).Caption & Label1(1).Caption

    Label2(1).Caption = Label1(2).Caption & Label1(3).Caption

  13. #13
    Staifour
    Guest
    i think that the count way is what you need but i suggest you change the Count variable to another name like Number and you must declare it so
    VB Code:
    1. Static Number
    2. Label2(Number).Caption=Label1(index).Caption
    3. Number=Number+1

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    118
    Thanks Guys, this seems to work for me now though:

    Select Case Index
    Case 0
    Label2(0).Caption = Label1(0).Caption
    Case 1
    Label2(0).Caption = Label1(1).Caption
    Case 2
    Label2(1).Caption = Label1(2).Caption
    Case 3
    Label2(1).Caption = Label1(3).Caption...etc......

    Is there a better way?
    or whats the better way?

  15. #15
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Catalonia
    Posts
    397
    This is a shorter code to do what you want
    VB Code:
    1. Dim number As Integer
    2. number = Int(Index / 2)
    3. Label2(number).Caption = Label1(Index).Caption
    label1 stored in label2
    ---0-------------------0
    ---1-------------------0
    ---2-------------------1
    ---3-------------------1
    ---4-------------------2
    ---5-------------------2
    ---6-------------------3
    ---7-------------------3
    Josep Mª

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