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
010110010001ADI TY3104200310450 001
010110010001ADI TY3104600310460 001
010110010001ADI TY3104800310490 001
010110010001DD8 320200032020000 1
010110010001ENA D 316110031628000 1
010110010001ENA D 319140032006000 1
010110010001GEM I 314350031435000 1
010110010001GEM I 315240031526000 1
010110010001HBO 314360031436000 1
010110010001SAN SK3113300311330 001
010110010001SIT MU3092400310240 001
010110010001TEJ NW3103900310400 001
010110010001TEJ NW3104700310470 001
010110010004DD8 307200030720000 1
010110010004DD8 320200032020000 1
010110010004ENA D 308080030808000 1
010110010004ENA D 308340030847000 1
010110010004GEM I 307420030803000 1
010110010004GEM I 308060030807000 1
010110010004SIT MU3065300306530 001
010110010004SIT MU3070000307000 001
* *
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
any help would be sincerely appreciated.
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
010110010001ADI TY3104200310450 001
010110010001ADI TY3104600310460 001
010110010001ADI TY3104800310490 001
010110010001DD8 320200032020000 1
010110010001ENA D 316110031628000 1
010110010001ENA D 319140032006000 1
010110010001GEM I 314350031435000 1
010110010001GEM I 315240031526000 1
010110010001HBO 314360031436000 1
010110010001SAN SK3113300311330 001
010110010001SIT MU3092400310240 001
010110010001TEJ NW3103900310400 001
010110010001TEJ NW3104700310470 001
010110010004DD8 307200030720000 1
010110010004DD8 320200032020000 1
010110010004ENA D 308080030808000 1
010110010004ENA D 308340030847000 1
010110010004GEM I 307420030803000 1
010110010004GEM I 308060030807000 1
010110010004SIT MU3065300306530 001
010110010004SIT MU3070000307000 001
* *
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
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
Comment