Closed Thread
Results 1 to 4 of 4

Thread: text file manipulations in vb6.0

  1. #1
    Ronin_paes Guest

    Smile text file manipulations in vb6.0

    Hello guys,

    I have a little bit of problem with textfile operations.I would like to some help from you smart people in the forum.

    I have a textfile by the name of 10117053.swd. This file contains a certain data in specific format like

    010110010001ADITY3104200310450001
    010110010001ADITY3104600310460001
    010110010001ADITY3104800310490001
    010110010001DD8 3202000320200001
    010110010001ENAD 3161100316280001
    010110010001ENAD 3191400320060001
    010110010001GEMI 3143500314350001
    010110010001GEMI 3152400315260001
    010110010001HBO 3143600314360001
    010110010001SANSK3113300311330001
    010110010001SITMU3092400310240001
    010110010001TEJNW3103900310400001
    010110010001TEJNW3104700310470001
    010110010004DD8 3072000307200001
    010110010004DD8 3202000320200001
    010110010004ENAD 3080800308080001
    010110010004ENAD 3083400308470001
    010110010004GEMI 3074200308030001
    010110010004GEMI 3080600308070001
    010110010004SITMU3065300306530001
    010110010004SITMU3070000307000001
    * *
    the first 12 numbers as homeid and the next 5 letters are channelname

    now i need to give the count of unique channels that are watched by the homeid in a new txtfile in the format

    homeid - count of unique channels that are watched by this id.

    for suppose homeid 010110010001 watched ADITY TWICE AND OTHER CHANNELS,BUT WE WANT THE COUNT OF THE UNIQUE CHANNELS THAT ARE WATCHED BY THESE HOMEID LIKE FOR ABOVE HOMEID 010110010001 HAS WATCHED 8 UNIQUE CHANNELS SO ON FOR EACH HOMEID.

    THE NEW TXTFILE SHOULD BE HOMEID

    010110010001 8
    010110010004 4 AND SO ON.


    NOW I AM NOT ABLE TO GET THIS i HAVE THE CODE pLEASE HAVE THE LOOK AT THE CODE
    here is the
    Code:
    Code:
    
    Option Explicit
    Dim fsys As New FileSystemObject
    Dim txtstream As TextStream
    Dim outstream As TextStream
    
    
    Private Sub cmdclick_Click()
    
     Dim j As Integer
     Dim searchline As String   ' reads each line of txtstream
     Dim filename As String     'file name which is dynamically generated
     Dim homeid As String   'to store 12 numbers
     Dim prevhomeid As String '  to comapre with other numbers
     Dim channelname As String '  to store channelname
     Dim prevchannelname As String  ' to compare prevchannelname
     Dim channelcount As Integer  ' to give channelcount
    
    
    
      If fsys.FileExists("C:\rohit program\exercise\SWD\" & filename) = True Then
                   MsgBox "file is open"
                 Else
                  MsgBox "file not found"
                 End If
                   
                   prevchannelname = ""
                   prevhomeid = ""
                   channelcount = 0
                   
        Set outstream = fsys.OpenTextFile("c:\channelcount.txt", ForWriting, True)
           Set txtstream = fsys.OpenTextFile("C:\rohit program\exercise\SWD\" & filename, ForReading, False)
                   Do Until txtstream.AtEndOfStream
                       searchline = txtstream.ReadLine
                          homeid = Mid(searchline, 1, 10)
                       If prevhomeid <> homeid Then
                                'do nothing`
                              outstream.WriteLine (homeid)
                            End If
                                 prevhomeid = homeid
                   Loop
                           
                               MsgBox " Process completed"
    End Sub
    any help would be sincerely appreciated.

    --------------------------------------------------------------------------------

    Reply
    Killer42
    Moderator
    2,625 Posts March 10th, 2007
    10:24 AM
    #2


    Re: text file operations with vb6.0
    --------------------------------------------------------------------------------

    Quote:
    Originally Posted by Ronin
    ...
    NOW I AM NOT ABLE TO GET THIS i HAVE THE CODE pLEASE HAVE THE LOOK AT THE CODE
    Code:
    Code:
    Option Explicit
    Dim fsys As New FileSystemObject
    Dim txtstream As TextStream
    Dim outstream As TextStream
    
    Private Sub cmdclick_Click()
    
     Dim j As Integer
     Dim searchline As String      ' reads each line of txtstream
     Dim filename As String        ' file name which is dynamically generated
     Dim homeid As String          ' to store 12 numbers
     Dim prevhomeid As String      ' to comapre with other numbers
     Dim channelname As String     ' to store channelname
     Dim prevchannelname As String ' to compare prevchannelname
     Dim channelcount As Integer   ' to give channelcount
    
    
    
      If fsys.FileExists("C:\rohit program\exercise\SWD\" & filename) = True Then
        MsgBox "file is open"
      Else
        MsgBox "file not found"
      End If
                   
      prevchannelname = ""
      prevhomeid = ""
      channelcount = 0
                   
      Set outstream = fsys.OpenTextFile("c:\channelcount.txt", ForWriting, True)
      Set txtstream = fsys.OpenTextFile("C:\rohit program\exercise\SWD\" & filename, ForReading, False)
      Do Until txtstream.AtEndOfStream
        searchline = txtstream.ReadLine
        homeid = Mid(searchline, 1, 10)
        If prevhomeid <> homeid Then
          'do nothing`
          outstream.WriteLine (homeid)
        End If
        prevhomeid = homeid
      Loop
       
      MsgBox " Process completed"
    End Sub
    Last edited by Jordan; 04-23-2007 at 08:26 AM. Reason: Added Code Tags

  2. CODECALL Circuit advertisement

     
  3. #2
    sqldud is offline Newbie
    Join Date
    Apr 2007
    Posts
    5
    Rep Power
    0
    Ronin

    The steps you have mentioned would be good for a single Home ID

    for multiple please try the following

    1. Declare an Array for HomeIDs
    2. Declare an Array for HomeIDCount

    Loop
    3. Get the HomeId one by one
    4. Check if the HomeId is available in any of the array
    5. If you find Home ID in array, then increment the count of HomeIDCount by one
    6. If you do not find Home ID in array, then Redim the HomeIDs array and store the Home ID, Redim the HomeIDCount array and store the count (1)

    Finally you will be having the count for all HomeIDs in HomeIDCount array

    Donot forget to preserve the array whenever you redimension

    Redim Preserve HomeIDs(i+1)
    Redim Preserve HomeIDCount(i+1)

  4. #3
    Jordan Guest
    Moved to Visual Basic Forum and added Code Tags

  5. #4
    Flame142 is offline Newbie
    Join Date
    Jan 2007
    Posts
    3
    Rep Power
    0
    Quote Originally Posted by sqldud View Post
    Ronin

    The steps you have mentioned would be good for a single Home ID
    yeah! It would!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Batch file to change text in a txt file?
    By Scarness in forum General Programming
    Replies: 3
    Last Post: 05-22-2011, 06:28 AM
  2. How can I let the text inside a text file ...
    By xxxxjayxxx in forum Java Help
    Replies: 1
    Last Post: 03-13-2011, 04:31 AM
  3. How to save the text in a text file ???
    By kresh7 in forum Visual Basic Programming
    Replies: 1
    Last Post: 04-11-2010, 02:03 AM
  4. Bitwise Manipulations in c
    By MrWannabe in forum C and C++
    Replies: 7
    Last Post: 09-23-2009, 07:11 PM
  5. Formatting Text in a text file help?
    By Djanvk in forum C and C++
    Replies: 2
    Last Post: 08-17-2008, 09:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts