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
any help would be sincerely appreciated.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
--------------------------------------------------------------------------------
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
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)
Moved to Visual Basic Forum and added Code Tags
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks