Textfile manipulations in vb6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronin
    New Member
    • Feb 2007
    • 25

    Textfile manipulations in vb6.0

    Hi friends,


    I am quite new to vb6.0 and not very familiar with the Vb filesystem object.

    I would be very helpful if you can help me in my problem.


    i have a txt file which contains some data which is arranged in certian order.

    for example

    000710010003 TMSNW7191300719 160001
    000710010005 ADITY7081600708 160001
    000710010005 ALPTL7195500719 550001
    000710010005 ALPTL7195700719 570001
    000710010005 ALPTL7195900719 590001
    000710010005 ENAD 720220072022000 1
    000710010005 ENAD 720250072025000 1
    000710010005 ENAD 722520072252000 1
    000710010005 ENAD 722560072257000 1
    000710010005 ENAD 723050072305000 1
    000710010005 ENAD 723080072308000 1
    000710010005 ENAD 723090072309000 1
    000710010005 ENAD 723150072316000 1
    000710010005 ETCPU7071800707 180001
    000710010005 GEMI 707360070741000 1


    Now I want to copy only the first 12 numbers ie 007 1001 0005 into a new notepad and also the numbers should not repeat itself in new notepad and also the total count of data(ie 12 digits numbers present in the old notepad).should be given. I am using filsystemobjecy in vb6.0

    it would also be very useful if you can tell me how if i want to replace the letters ENAD WITH GEMI ,how could i do this through notepad.

    Pls help me guys,its urgent,
  • Ronin
    New Member
    • Feb 2007
    • 25

    #2
    Originally posted by Ronin
    Hi friends,


    I am quite new to vb6.0 and not very familiar with the Vb filesystem object.

    I would be very helpful if you can help me in my problem.


    i have a txt file which contains some data which is arranged in certian order.

    for example

    000710010003 TMSNW7191300719 160001
    000710010005 ADITY7081600708 160001
    000710010005 ALPTL7195500719 550001
    000710010005 ALPTL7195700719 570001
    000710010005 ALPTL7195900719 590001
    000710010005 ENAD 720220072022000 1
    000710010005 ENAD 720250072025000 1
    000710010005 ENAD 722520072252000 1
    000710010005 ENAD 722560072257000 1
    000710010005 ENAD 723050072305000 1
    000710010005 ENAD 723080072308000 1
    000710010005 ENAD 723090072309000 1
    000710010005 ENAD 723150072316000 1
    000710010005 ETCPU7071800707 180001
    000710010005 GEMI 707360070741000 1


    Now I want to copy only the first 12 numbers ie 007 1001 0005 into a new notepad and also the numbers should not repeat itself in new notepad and also the total count of data(ie 12 digits numbers present in the old notepad).should be given. I am using filsystemobjecy in vb6.0

    it would also be very useful if you can tell me how if i want to replace the letters ENAD WITH GEMI ,how could i do this through notepad.

    Pls help me guys,its urgent,
    Hey guys I finally got the code how to do it,anyways I would like to share it with you,so that anyboy who needs help can view it and utilise it.
    Code:
    option explicit
    Dim Fsys As New FileSystemObject
    Dim Tstream As TextStream
    Dim outstream As TextStream
    ' Declaring variable
    Dim homeid As String
    Dim prevhomid As String
    Dim intfound As Integer
    Dim InputLine As String
    
    Set outstream = Fsys.OpenTextFile("c:\datafile.txt", ForWriting, True)
    Set Tstream = Fsys.OpenTextFile("C:\Ronin program\exercise\SWD\" & filename, ForReading)
      Do Until Tstream.AtEndOfStream
          InputLine = Tstream.ReadLine
          homeid = Mid(InputLine, 1, 12)
          If prevhomid = homeid Then
          prevhomid = homeid
                
      Else
                
          intfound = intfound + 1
          prevhomid = Mid(homeid, 10, 12)
          outstream.WriteLine (homeid)
          prevhomid = homeid
      End If
    Anyways guys i have a new problem suppose if i do not want the number which ends with 05 how should i go with it.any help would be appreciated.
    Last edited by Killer42; Feb 23 '07, 02:10 AM. Reason: Please use appropriate tags around your code

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by Ronin
      ...Anyways guys i have a new problem suppose if i do not want the number which ends with 05 how should i go with it.any help would be appreciated.
      Thanks for sharing that with everyone, Ronin. Even though you have resolved your issue, it's good to have the answer handy for anyone else who comes searching.

      As for the 05, perhaps the simplest would be to use the Like operator. Or maybe just the Right$() function. Here are two possible tests...
      Code:
      If homeid Like "*05" Then
        [I][B]or[/B][/I]
      If Right$(homeid, 2) = "05" Then
      By the way, it doesn't make much sense to say
      Code:
      If prevhomid = homeid Then
        prevhomid = homeid
      You are setting prevhomid to the same value that's already in it. This is unnecessary. If you want, you can just leave a code block empty. For example...
      Code:
      If prevhomid = homeid Then
        ' No need to do anything here.
      Else
      Of course, in this case you can write a more compact version such as...
      Code:
      If prevhomid <> homeid Then
        intfound = intfound + 1
        ' Etc...

      Comment

      • Ronin
        New Member
        • Feb 2007
        • 25

        #4
        Originally posted by Killer42
        Thanks for sharing that with everyone, Ronin. Even though you have resolved your issue, it's good to have the answer handy for anyone else who comes searching.

        As for the 05, perhaps the simplest would be to use the Like operator. Or maybe just the Right$() function. Here are two possible tests...
        Code:
        If homeid Like "*05" Then
          [I][B]or[/B][/I]
        If Right$(homeid, 2) = "05" Then
        By the way, it doesn't make much sense to say
        Code:
        If prevhomid = homeid Then
          prevhomid = homeid
        You are setting prevhomid to the same value that's already in it. This is unnecessary. If you want, you can just leave a code block empty. For example...
        Code:
        If prevhomid = homeid Then
          ' No need to do anything here.
        Else
        Of course, in this case you can write a more compact version such as...
        Code:
        If prevhomid <> homeid Then
          intfound = intfound + 1
          ' Etc...
        Thanks Killer 42

        Comment

        Working...