Ronin_paes 0 Newbie Poster

Hello to all vb community members,

I am quite new to vb6.0 and i am stuck on a little bit of problem,if any of u people can help me there,it would be wonderful and i will be thankful to u.

now the problem,

I have a textfile by the name 10117055.txt

This text file contains data in fixed format like

010110010001DD8 5073100507310001
010110010001ENAD 5073000507300001
010110010001ETV2 5073200507330001
010110010001ETV2 5073600507360001
010110010001ETV2 5073700508080001
010110010003ETV2 5073600507360001
010110010004GEMI 5111200511330001
010110010004SITMU5094200510590001
010110010004SITMU5113400511500001
010110010098DD8 50731005073100 1
010110010098ENAD 50730005073000 1
010110010098ETV2 50732005073300 1
010110010098ETV2 50736005080800 1
010110010098ETV2 50941005094100 1
010110010098GEMI 51112005113300
010110030001ENAD 5103600510460001
010110030001ENAD 5105200511170001
010110030001GEMI 5104800510510001
010110030001MAATV5104700510470001
010110030001NDT245111800511190001
010110030001POGO 5092400510070001
010110030001POGO 5100800510350001
010110030001SITMU5090500509060001
010110030001SITMU5090800509230001
010110030002ADITY5075200508000001
010110030002ADITY5181400518320001

And so on, now let me explain what these data means

the first 10 digit is homeid followed by the next 2digit which is memberid and the next letters are channelname,now channelname cannot be more than 5 letters.

so let me sum it up

0101100100 homeid 01 memberid and DD8 channelname.

now i want to give the count of all the unique channels that are watched by these homeid in a new textfile like this

suppose homeid 0101100100 has watched 10 unique channels then we have to have the data in a new text filein this format

0101100100 10

and so on for each unique homeid.like now after homeid 0101100100,we have homeid 0101100300,suppose it has watched 4 unique channels then my new textfile will contain

0101100100 10
0101100300 4
and so on

Here is a code that i have written

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 ' inputline to read txtstream
 Dim filename As String   ' to dynamically generate filename
 Dim homeid As String    ' to have homeid
 Dim prevhomeid As String  ' to compare to homeid
 Dim channelname As String ' to store channelname
 Dim channelcount As Integer ' to count the numbers of unique channels
 Dim channelarray(0 To 100000) As String   'to store the homeid and channelname
 Dim prevchannelarray(0 To 100000) As String
 Dim csort As String
 'Dim prevcarray As String
 Dim i As Integer
 
 
    For j = 0 To lstmarket.ListCount - 1
     If lstmarket.Selected(j) = True Then
  
         
           If Len(Trim(txtyear.Text)) > 2 Or IsNumeric(Trim   (txtyear.Text)) = False Then
              MsgBox "this should be 2 digit number "
              txtyear.Text = ""
              txtyear.SetFocus
           Exit Sub
           End If
           
           If Trim(txtweek) <= 9 And Len(Trim(txtweek)) < 2 Or IsNumeric(txtweek.Text) = False Then
              txtweek = "0" & Trim(txtweek)
           End If
           
           If Trim(txtday) > 7 Or IsNumeric(txtday) = False Then
                MsgBox "Please enter number which is equal to or less than 7"
                txtday.Text = ""
                txtday.SetFocus
           Exit Sub
           End If
               
           filename = lstmarket.List(j) & Trim(txtyear) & Trim(txtweek) & Trim(txtday) & ".swd"
              MsgBox ("you have selected the following" & filename)
     End If
   Next j
             
  '********main code for listing all the channels that the house id watch*******
            
             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
              prevchannelarray(k) = ""
    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)
                      channelname = Mid(searchline, 13, 5)
                       channelarray(i) = homeid & channelname
                         If channelarray(i) <> channelarray(i + 1) Then
                           'do nothing
                            channelarray(k) = channelarray(i)
                            If InStr(1, channelarray(i), channelname, vbTextCompare) = False Then
                                channelcount = channelcount + 1
                            'outstream.WriteLine (channelarray(k))
                             outstream.WriteLine (channelarray(i)) & channelcount
                            End If
                         End If
                           channelarray(i + 1) = channelarray(i)
                        
                        
                          
                    
                             
                        
                             
                       
               Loop
                   MsgBox "process completed"

i m not able to get desired output,pls help:confused:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.