VB6 and ASCII text files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kimmelsd33
    New Member
    • Dec 2009
    • 29

    VB6 and ASCII text files

    Using VB6, is there any special way of reading an ascii text file, that does not have any delimiters? The rows of data are seperated into seperate columns, but there is not "space" delimiter. Has me confused. I am trying to read in about 10 columns of data, with x number of rows. Any help or suggestions? Thanks
    Attached Files
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Your fields are delimeted by a tab character (vbTab)... so you would split using vbTab...



    Good Luck

    Comment

    • kimmelsd33
      New Member
      • Dec 2009
      • 29

      #3
      I tried using vbTab and I am getting an error. Not sure what else to do.

      Comment

      • kimmelsd33
        New Member
        • Dec 2009
        • 29

        #4
        This is the code I'm using to split the line:
        Code:
        strLine = TrimAll2(objstream.Readline)
        myarray = Split(strLine, vbTab) 'use tab to create space
        'read into variables
        lithdepth = Format(Trim(myarray(0)), "0")
        shale = Trim(myarray(1))
        silt = Trim(myarray(2))
        sand = Trim(myarray(3))
        chalk = Trim(myarray(4))
        lime = Trim(myarray(5))
        dolo = Trim(myarray(6))
        anhy = Trim(myarray(7))
        coal = Trim(myarray(8))
        chert = Trim(myarray(9))
        nosamp = Trim(myarray(10))
        This is the function code that processes each line:
        Code:
        Function TrimAll2(Str)
            '***remove all non ASCI chrs and reduce internal whitespace to single
            Dim i, strTemp, strOut, strCh
        
            strTemp = Str
            For i = 1 To Len(strTemp)
                strCh = Mid(strTemp, i, 1) '***look at each character in turn
                '***if the chr is a space and the previous added chr was a space ignore it
                '***otherwise add it on
                If Not (strCh = " " And Right(strOut, 1) = " ") And ((Asc(strCh) >= 64 And Asc(strCh) <= 122) _
                    Or (Asc(strCh) >= 48 And Asc(strCh) <= 57) Or Asc(strCh) = 32 Or strCh = ".") Then
                        strOut = strOut & strCh
                End If
            Next
            TrimAll2 = strOut
        End Function
        For some reason, vbTab is still giving me an error when reading the line into an assigned variable.

        Comment

        • vb5prgrmr
          Recognized Expert Contributor
          • Oct 2009
          • 305

          #5
          Because the tab character equates to the ascii value of 9, you are removing the tabs from the string and thus are unable to split on the tab character...



          Good Luck

          Comment

          • kimmelsd33
            New Member
            • Dec 2009
            • 29

            #6
            So, do I need to recode the function? Or can I add to it? Or what would you suggest? Thanks for the response.

            Comment

            • vb5prgrmr
              Recognized Expert Contributor
              • Oct 2009
              • 305

              #7
              From what I remember of your file, I would think that you could skip the removal function and go strait to spliting on vbtab but just to be sure check the results.



              Good Luck

              Comment

              • kimmelsd33
                New Member
                • Dec 2009
                • 29

                #8
                Thanks. I just skipped the function process and it is working.

                Comment

                Working...