text file manipulations

Reply

Join Date: Mar 2007
Posts: 1
Reputation: Ronin_paes is an unknown quantity at this point 
Solved Threads: 0
Ronin_paes Ronin_paes is offline Offline
Newbie Poster

text file manipulations

 
0
  #1
Mar 23rd, 2007
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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Option Explicit
  3. Dim fsys As New FileSystemObject
  4. Dim txtstream As TextStream
  5. Dim outstream As TextStream
  6.  
  7.  
  8.  
  9. Private Sub cmdclick_Click()
  10. Dim j As Integer
  11. Dim searchline As String ' inputline to read txtstream
  12. Dim filename As String ' to dynamically generate filename
  13. Dim homeid As String ' to have homeid
  14. Dim prevhomeid As String ' to compare to homeid
  15. Dim channelname As String ' to store channelname
  16. Dim channelcount As Integer ' to count the numbers of unique channels
  17. Dim channelarray(0 To 100000) As String 'to store the homeid and channelname
  18. Dim prevchannelarray(0 To 100000) As String
  19. Dim csort As String
  20. 'Dim prevcarray As String
  21. Dim i As Integer
  22.  
  23.  
  24. For j = 0 To lstmarket.ListCount - 1
  25. If lstmarket.Selected(j) = True Then
  26.  
  27.  
  28. If Len(Trim(txtyear.Text)) > 2 Or IsNumeric(Trim (txtyear.Text)) = False Then
  29. MsgBox "this should be 2 digit number "
  30. txtyear.Text = ""
  31. txtyear.SetFocus
  32. Exit Sub
  33. End If
  34.  
  35. If Trim(txtweek) <= 9 And Len(Trim(txtweek)) < 2 Or IsNumeric(txtweek.Text) = False Then
  36. txtweek = "0" & Trim(txtweek)
  37. End If
  38.  
  39. If Trim(txtday) > 7 Or IsNumeric(txtday) = False Then
  40. MsgBox "Please enter number which is equal to or less than 7"
  41. txtday.Text = ""
  42. txtday.SetFocus
  43. Exit Sub
  44. End If
  45.  
  46. filename = lstmarket.List(j) & Trim(txtyear) & Trim(txtweek) & Trim(txtday) & ".swd"
  47. MsgBox ("you have selected the following" & filename)
  48. End If
  49. Next j
  50.  
  51. '********main code for listing all the channels that the house id watch*******
  52.  
  53. If fsys.FileExists("C:\rohit program\exercise\SWD\" & filename) = True Then
  54. MsgBox "file is open"
  55. Else
  56. MsgBox "file not found"
  57. End If
  58.  
  59. 'prevchannelname = ""
  60. prevhomeid = ""
  61. channelcount = 0
  62. prevchannelarray(k) = ""
  63. Set outstream = fsys.OpenTextFile("c:\channelcount.txt", ForWriting, True)
  64. Set txtstream = fsys.OpenTextFile("C:\rohit program\exercise\SWD\" & filename, ForReading, False)
  65. Do Until txtstream.AtEndOfStream
  66. searchline = txtstream.ReadLine
  67. homeid = Mid(searchline, 1, 10)
  68. channelname = Mid(searchline, 13, 5)
  69. channelarray(i) = homeid & channelname
  70. If channelarray(i) <> channelarray(i + 1) Then
  71. 'do nothing
  72. channelarray(k) = channelarray(i)
  73. If InStr(1, channelarray(i), channelname, vbTextCompare) = False Then
  74. channelcount = channelcount + 1
  75. 'outstream.WriteLine (channelarray(k))
  76. outstream.WriteLine (channelarray(i)) & channelcount
  77. End If
  78. End If
  79. channelarray(i + 1) = channelarray(i)
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. Loop
  89. MsgBox "process completed"

i m not able to get desired output,pls help
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC