Results 1 to 4 of 4

Thread: VB6 Moving Array Elements into Textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    5

    VB6 Moving Array Elements into Textbox

    Hi all,

    I have an array, and I want to copy certain fields of a row and column to a textbox.

    The program is to evaluate the 5th column of every row. If the 5th column has a '1', it copies the 1st column of that row to the text box. In other words, if a given row has the elements 7 2 3 4 1 5, since the 5th element is equal to one, copy the first element of that row to the text box which is 7.

    My problem is, it only copies the last instance of column 5 having a 1, and leaves the other rows out. How can I copy all of the instances of this to the text box instead of just the last?

    What I have is below.

    Code:
    For R = 0 To endrows                   ' Cycle through all rows 
        If (B(R, C) = "1") Then              ' If the 5th column of a row has a 1
            Text1.Text = B(R, C)            ' then copy the 1 value in that row to the textbox
        End If
    Next R
    Last edited by terh; Jan 11th, 2013 at 01:40 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    5

    Re: VB6 Moving Array Elements into Textbox

    Found quick solution. Sorry for wasting the post. All I added was a carriage return then added then incremented the Textbox.

    Code:
    For R = 0 To endrows
        If (B(R, 4) = "1") Then
            Text1.Text = B(R, 2) + vbCrLf + Text1.Text
        End If
    Next R

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: VB6 Moving Array Elements into Textbox

    Glad you resolved it...you should mark this thread as resolved. (Menu, Thread Tools).
    Just curious, why not use a listbox instead of a multiline textbox....would be easier.

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: VB6 Moving Array Elements into Textbox

    not that this is wrong but if you want to add things backwards you got it right
    Code:
    For R = 0 To endrows
        If (B(R, 4) = "1") Then
            Text1.Text = B(R, 2) + vbCrLf + Text1.Text
        End If
    Next R
    if you want to add in the right order use this instead
    Code:
    For R = 0 To endrows
        If (B(R, 4) = "1") Then
            Text1.Text = Text1.Text & B(R, 2) & vbCrLf 
        End If
    Next R
    please do not use a + sign to add strings together, you might get away with it but eventually you might run into some errors use the & sign

Tags for this Thread

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