Results 1 to 7 of 7

Thread: [RESOLVED] Ordering of data

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Resolved [RESOLVED] Ordering of data

    Code:
     For i = 0 To txtInfo.Count - 1
        If Not txtInfo(i) = vbNullString Then
            Print #filenum, lblinfo(i) & " " & txtInfo(i)
            strbuffer = strbuffer + vbCrLf + lblinfo(i).Caption & " " & txtInfo(i).Text
        End If
    Next i
        
    For i = 0 To cmbInfo.Count - 1
        If Not cmbInfo(i) = vbNullString Then
            Print #filenum, lblsm(i) & " " & cmbInfo(i)
            strbuffer = strbuffer + vbCrLf + lblsm(i).Caption & " " & cmbInfo(i).Text
        End If
    Next i
    That is the code i am using at the moment to write some stuff to a text file (don't worry to much about strbuffer thats for the clipboard) now what i need is to print the data to the text file but ordered in such a way that cmbinfo(0 and 1) are positioned in the middle of the txtInfo(i) control array.

    So the output would be...

    txtInfo(0)
    txtInfo(1)
    txtInfo(2)
    txtInfo(3)
    txtInfo(4)
    cmbInfo(0)
    cmbInfo(1)
    txtInfo(5)
    ...

    Just to remind you guys i cant add both control arrays together as they aren't identical controls.

    Any ideas? I need this as soon as possible! Otherwise i will have to remove the control array and do it a much slower way

  2. #2

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Ordering of data

    Hmm maybe a select case? I am using an if statement at the moment only because it is shorter. But if there is a better way please do tell

  3. #3

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Ordering of data

    Came up with this messy method

    Remember it is 1:00am here so be gentle

    It works but if anyone can clean it up or something that would be nice

    Code:
    For i = 0 To txtInfo.Count - 1
         If Not txtInfo(i) = vbNullString Then
              If i = 3 Then
                   Print #filenum, lblsm(0) & " " & cmbInfo(0)
                   strbuffer = strbuffer + vbCrLf + lblsm(0).Caption & " " & cmbInfo(0).Text
              ElseIf i = 4 Then
                   Print #filenum, lblsm(1) & " " & cmbInfo(1)
                   Print #filenum, lblinfo(3) & " " & txtInfo(3)
                   Print #filenum, lblinfo(4) & " " & txtInfo(4)
                   strbuffer = strbuffer + vbCrLf + lblsm(1).Caption & " " & cmbInfo(1).Text _
                                    + vbCrLf + lblinfo(3).Caption & " " & txtInfo(3).Text + vbCrLf _
                                    + lblinfo(4).Caption & " " & txtInfo(4).Text
              Else
                   Print #filenum, lblinfo(i) & " " & txtInfo(i)
                   strbuffer = strbuffer + vbCrLf + lblinfo(i).Caption & " " & txtInfo(i).Text
              End If
         End If
    Next i

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Ordering of data

    Add a Boolean variable, a Select Case, and nest the cmb inf array as follows:
    Code:
    Dim CmbInf As Boolean
    
    For i = 0 To txtInfo.Count - 1
        Select Case i
        Case Is < 5
            If Not txtInfo(i) = vbNullString Then
                Print #filenum, lblinfo(i) & " " & txtInfo(i)
                strbuffer = strbuffer + vbCrLf + lblinfo(i).Caption & " " & txtInfo(i).Text
            End If
        Case Else
            If CmbInf = False Then
                For j = 0 To cmbInfo.Count - 1
                    If Not cmbInfo(j) = vbNullString Then
                        Print #filenum, lblsm(j) & " " & cmbInfo(j)
                        strbuffer = strbuffer + vbCrLf + lblsm(j).Caption & " " & cmbInfo(j).Text
                    End If
                Next j
                CmbInf = True
            End If
            If Not txtInfo(i) = vbNullString Then
                Print #filenum, lblinfo(i) & " " & txtInfo(i)
                strbuffer = strbuffer + vbCrLf + lblinfo(i).Caption & " " & txtInfo(i).Text
            End If
        End Select
    Next i
    Doctor Ed

  5. #5

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Ordering of data

    Sorry for the delay fixed it

    Here is what i came up with...

    Code:
    For i = 0 To txtInfo.Count - 1
        If Not txtInfo(i) = vbNullString Then
            If i = 3 Then
                For j = 0 To cmbInfo.Count - 1
                    If Not cmbInfo(j) = vbNullString Then
                        Print #filenum, lblsm(j) & " " & cmbInfo(j)
                        strbuffer = strbuffer + vbCrLf + lblsm(j).Caption & " " & cmbInfo(j).Text
                    End If
                Next j
            End If
                    
            Print #filenum, lblinfo(i) & " " & txtInfo(i)
            strbuffer = strbuffer + vbCrLf + lblinfo(i).Caption & " " & txtInfo(i).Text
        End If
    Next i

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: [RESOLVED] Ordering of data

    Good show, Paul. I realize you marked the post resolved, but based on your original order condition for writing the information as shown in Post #1, I think you want "If i = 5 Then" rather than "If i = 3 Then" on the third line.

    Just my $0.02.
    Doctor Ed

  7. #7

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [RESOLVED] Ordering of data

    Nah sorry that was just a total example

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