How to extract data from a text file using VB6?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandesh Pradhan
    New Member
    • Jan 2011
    • 1

    How to extract data from a text file using VB6?

    The content of the text file look something like this :

    CONTINUATION TEXT 0002

    PATIS/00977PATISC/NEPCBK1V7131058 3/013 10-06-01 10:32:46
    7724 NetM NETMPATN 2937/08564

    REGISTRATION POINT: BHK1424 ORIGIN OBJECT:
    RGPT TYPE: DOUBLE DESTINATION OBJECT:

    TRA TIM CALL NUMBER DURATION NUMBER OF A-SIDE B-SIDE
    GRP GRP DURATION OF CALLS BEF.ANSWER SEIZURES CHARGES CHARGES
    ---+---+----------+---------+----------+----------+----------+----------
    1 1 123 856 0 0 0 0
    INTERRUPTION TEXT JOB 7724



    >>>>>> I want to extract Registration point: value(single string) and the number values below in the same line in text and/or excel sheet as below for the whole file.

    BHK1424 1 1 123 856 0 0 0 0

    I would be very grateful if some VB expert would lend me some advice.


    Thanks !!
    Sandesh
  • Rodney Roe
    New Member
    • Oct 2010
    • 61

    #2
    Here's somethingyou can use

    Code:
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim fs, f as object
    
    Public Sub getInfo()
    Dim firstVal, finalVal, strContents As String
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("fullpath", ForReading) 'put full path of text file in place of FullPath
    
    Do Until InStr(1, strContents, "REGISTRATION POINT") = 1
        strContents = f.readline
    Loop
    firstVal = Mid(strContents, 21, 7)
    Do
        strContents = f.readline
    Loop Until InStr(1, strContents, "+") >= 1  'this is assuming that the numbers allways follow the line with the + signs
    strContents = f.readline
    finalVal = firstVal + " " + strContents
    End Sub

    Comment

    • Rodney Roe
      New Member
      • Oct 2010
      • 61

      #3
      Sorry i forgot to add this to the end of the vbcode,

      Code:
      f.close
      set f = nothing
      set fs = nothing

      Comment

      Working...