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 -
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.
42 10290
...
NOW I AM NOT ABLE TO GET THIS i HAVE THE CODE pLEASE HAVE THE LOOK AT THE 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
Can you give us a clue as to what you don't like about your code? What does it do wrong, or not do?
One or two things did occur to me when I glanced at the code... - Your code assumes the file is sorted. Is that a reasonable assumption in this case?
- You are picking up the first 10 characters as the homeid, but you told us it was 12.
- Assuming the file is sorted, you look as though you're probably picking up each homeid alright. Within each one, I guess you just need to do a similar check for previous channel and report each new one which shows up.
-
-
-
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)
- 'here check this homeid with the distinct homeid in array say prevHomeId()
-
'if this home id doesnot exists then add this to array
-
'then again run this loop here u will check home id with your arraylist
-
' increment the counter and finally u'll get the ans
-
If prevhomeid <> homeid Then
-
'do nothing`
-
outstream.WriteLine (homeid)
-
End If
-
prevhomeid = homeid
-
Loop
-
-
MsgBox " Process completed"
-
End Sub
-
-
-
-
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)
- 'here check this homeid with the distinct homeid in array say prevHomeId()
-
'if this home id doesnot exists then add this to array
-
'then again run this loop here u will check home id with your arraylist
-
' increment the counter and finally u'll get the ans
-
If prevhomeid <> homeid Then
-
'do nothing`
-
outstream.WriteLine (homeid)
-
End If
-
prevhomeid = homeid
-
Loop
-
-
MsgBox " Process completed"
-
End Sub
-
Sir,you are right that i should use an array ,but my problem is that i do not know how to put the homeid value in arrays and compare them,basically i know what are arrays but ,how they store data or manipulate data, i have very little knowledge,perha ps any help on this would be very useful for me.
Right know i am goind through a topic on arrays and lets see if i am able to do this.Thank you sir for your help.
Sir,you are right that i should use an array ,but my problem is that i do not know how to put the homeid value in arrays and compare them,basically i know what are arrays but ,how they store data or manipulate data, i have very little knowledge,perha ps any help on this would be very useful for me.
Right know i am goind through a topic on arrays and lets see if i am able to do this.Thank you sir for your help.
Keep us posted on how it goes.
However, as long as the items are definitely in sorted sequence, you don't need to use an array - your technique of checking against the previous item will work fine. You just need to extend it to handle the channels in a similar way.
On the other hand, if they are not sorted, then yes, you will need to use something like an array to keep track of those which have already been handled.
Keep us posted on how it goes.
However, as long as the items are definitely in sorted sequence, you don't need to use an array - your technique of checking against the previous item will work fine. You just need to extend it to handle the channels in a similar way.
On the other hand, if they are not sorted, then yes, you will need to use something like an array to keep track of those which have already been handled.
Sir, It seems I am not able to clearly define what i actually want. so let me try it once again
Sir ,I have textfile which have name like "10117051.s wd" now this is a file which contains data of television audio Ratings.
The data in this file have systematic pattern so that i can identify it.
for example take a look at this line
010110010001ADI TY1114700111470 001
now the first 12 numbers ie 010110010001 are homeids followed channel name ie ADITY.
Now sir yes,u r right that these file are sorted,but I do not want to sort these file
I want a code which can give the count of unique channels that is watched by this id in specific format in a new textfile which should have the data like
010110010001 8 where 8 is the number of unique channels watched by this id and so on for every unique homeid.
now sir,my biggest concern is i am not good with arrays and how to use them,hence i am facing problem.
if you could guide me, i would be very thankful.
Thank you
Keep us posted on how it goes.
However, as long as the items are definitely in sorted sequence, you don't need to use an array - your technique of checking against the previous item will work fine. You just need to extend it to handle the channels in a similar way.
On the other hand, if they are not sorted, then yes, you will need to use something like an array to keep track of those which have already been handled.
sir I m trying to implement arrays in my code but i am unable to do so,pls help me.here is the sample code that i m trying to do
[code]
Private Sub cmdclick_Click( )
Dim j As Integer
Dim searchline As String
Dim filename As String
Dim homeid As String
Dim prevhomeid As String
Dim channelname As String
Dim prevchannelname As String
Dim channelcount As Integer
Dim channelarray() As String
For j = 0 To lstmarket.ListC ount - 1
If lstmarket.Selec ted(j) = True Then
If Len(Trim(txtyea r.Text)) > 2 Or IsNumeric(Trim( txtyear.Text)) = False Then
MsgBox "this should be 2 digit number "
txtyear.Text = ""
txtyear.SetFocu s
Exit Sub
End If
If Trim(txtweek) <= 9 And Len(Trim(txtwee k)) < 2 Or IsNumeric(txtwe ek.Text) = False Then
txtweek = "0" & Trim(txtweek)
End If
If Trim(txtday) > 7 Or IsNumeric(txtda y) = 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\exercis e\SWD\" & filename) = True Then
MsgBox "file is open"
Else
MsgBox "file not found"
End If
prevchannelname = ""
prevhomeid = ""
channelcount = 0
Set outstream = fsys.OpenTextFi le("c:\channelc ount.txt", ForWriting, True)
Set txtstream = fsys.OpenTextFi le("C:\rohit program\exercis e\SWD\" & filename, ForReading, False)
Do Until txtstream.AtEnd OfStream
searchline = txtstream.ReadL ine
homeid = Mid(searchline, 1, 10)
'I am tring put values into the array but it is not going in instead it is giving err like cannot assign an array
'here is what i ma trying to do
'channelarray(s earchline)=chan nelarray
i's this right
any examples or help would be very helpful
'prevhomeid (homeid)
If prevhomeid <> homeid Then
'do nothing`
channelname = Mid(homeid, 12, 5)
If prevchannelname <> channelname Then
channelcount = channelcount + 1
End If
outstream.Write Line (homeid)
End If
prevhomeid = homeid
Loop
MsgBox " Process completed"
End Sub
[\code]
have a look at this if this is the right way. -
-
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
-
Dim filename As String
-
Dim homeid As String
-
Dim prevhomeid As String
-
Dim channelname As String
-
Dim prevchannelname As String
-
Dim channelcount As Integer
-
Dim channelarray(100000) 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
-
-
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)
-
For i = 0 To channelcount
-
If channelarray(i) <> homeid Then
-
channelarray(i) = homeid
-
End If
-
If homeid <> channelarray(i) Then
-
channelcount = channelcount + 1
-
'channelcount = channelcount + 1
-
End If
-
-
Next i
-
'prevhomeid (homeid)
-
'If prevhomeid <> homeid Then
-
'If channelarray(i) <> homeid Then
-
-
-
'do nothing`
-
'channelname = Mid(homeid, 12, 5)
-
'If prevchannelname <> channelname Then
-
'channelcount = channelcount + 1
-
'End If
-
'outstream.WriteLine (homeid)
-
outstream.WriteLine (homeid) & vbTab & channelcount
-
' End If
-
'prevhomeid = homeid
-
Loop
-
-
MsgBox " Process completed"
-
End Sub
-
-
still i am not able to get the desired output as mentioned above
I'm short on time, so I'm going to address one thing at a time. This piece of code... - For i = 0 To channelcount
-
If channelarray(i) <> homeid Then
-
channelarray(i) = homeid
-
End If
-
If homeid <> channelarray(i) Then
-
channelcount = channelcount + 1
-
End If
-
Next i
...has some serious problems. - For starters, is this array supposed to hold channels, or homeids? If the former, then you've used it in the wrong place. If the latter, then the name is confusing.
- If you follow the execution you will find that it is simply going to place each homeid in turn into the first (the "zeroth") occurence of the array.
- The second condition tested (homeid <> channelarray(i)) can never possibly be True, since you have just just set the two variables equal.
That's enough for today's lesson. :)
I'm short on time, so I'm going to address one thing at a time. This piece of code... - For i = 0 To channelcount
-
If channelarray(i) <> homeid Then
-
channelarray(i) = homeid
-
End If
-
If homeid <> channelarray(i) Then
-
channelcount = channelcount + 1
-
End If
-
Next i
...has some serious problems.- For starters, is this array supposed to hold channels, or homeids? If the former, then you've used it in the wrong place. If the latter, then the name is confusing.
- If you follow the execution you will find that it is simply going to place each homeid in turn into the first (the "zeroth") occurence of the array.
- The second condition tested (homeid <> channelarray(i)) can never possibly be True, since you have just just set the two variables equal.
That's enough for today's lesson. :)
thnks for the reply,now let me thnk once again I have a textfile which has some homeids and channelname .
like
010110010001DD8 507310050731000 1
010110010001DD8 507310050731000 1
010110010001ENA D 507300050730000 1
010110010001ETV 2 507320050733000 1
010110010001ETV 2 507360050736000 1
010110010001ETV 2 507370050808000 1
010110010003ETV 2 507360050736000 1
010110010003ETV 2 507370050808000 1
010110010004ETV 2 507360050736000 1
010110010004ETV 2 507370050808000 1
010110010004ETV 2 509410050941000 1
010110010004GEM I 511120051133000 1
now the first 10 digit is homeid next 2 is member id ie
0101100100 is homeid and 01 is memeber id and next is channelname and channelname cannot be more than 5 letters.
now i want to compare these homeid in such a way so that i can get the count of unique channels that are watched by these homeids in a new text file in the format
0101100100 3 where 010110010 is homeid and 3 is the count of unique channels that is watched by these id,so on for every id.
any help or idea how could i do it.sir i am not that at programming but i m still trying,i sincerely thank u for ur help.:)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew Chanter |
last post by:
I am writing a little routine to perform the following operations from an
Acces 97 mdb:
1. create a fixed width text file
2. create/establish a table type link to the text file in Access
3. allow the user to view the text contained in the text file via an Access
form.
I have been able to achieve this, albeit with one major limitation. That is
that the name of the text file needs to be known prior to runtime. In other
|
by: siliconwafer |
last post by:
Hi All,
If I open a binary file in text mode and use text functions to
read it then will I be reading numbers as characters or actual
values?
What if I open a text file and read it using binary read functions.
-Siliconwafer
|
by: Lalasa |
last post by:
Hi,
Can anybody tell me how many cpu cycles File.copy would take and
how many cpu cycles File.Move would take?
CFile::Rename in C++ takes just one cpu cycle. As there is no
File.Rename in C#, I am worried about using File.copy or File.Move
which would do the same job of renaming a file but I want it done in
just one cpu cycle.
|
by: Rob Leyshon |
last post by:
For whatever reason I am unable to use FileSystemObject
e.g. using the code:
Dim fso As New FileSystemObject
Everytime my program hits this it gives the error:
"Compile error: User-defined type not defined"
Am I missing something?
|
by: Andrew |
last post by:
Hi, im trying to create a small function which can create a binary tree
from the entries in a text file and after that we can perform all the
usual operations like search, insert and delete etc. Now i have entries
something like this
IPaddress Phone No
192.168.2.1 2223447689
192.168.2.2 3334449898
192.168.2.3 5667869089
| |
by: ACC |
last post by:
Hi!
I'm developing an application to analyze some information that is
inside a text file. The size of the text file goes from 50Mb to
220Mb...
The text file is like a table, with "rows" and "columns", and several
"cells" represent an objects in my application.
What I need to do is, read the text file line by line, parse the
|
by: JJ |
last post by:
I have a need to input a large tab delimited text file, which I will parse
to check it has the expected columns, before allowing the user to submit it
to the database. The user may paste the file into a textbox, or upload it
(haven't decided yet).
The problem I have is that the text file consists of around 3000 lines, and
I want to display the formatted columns to the user before submitting it to
the database (perhaps allowing them to...
|
by: parthaspanda22 |
last post by:
How can I get to discard the contents of a text file from a specified
offset(
say, obtained from ftell)?
Sincerely.
|
by: tabassumpatil |
last post by:
Please send the c code for:
1.STACK OPERATIONS :
Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2.
2.QUEUE OPERATIONS :
Write a program to implement DOUBLE ENDED QUEUE operations
a) Use names as data to perform all operations like enqueue,dequeue,print,etc.
b)Use students records as data to perform the same operations.
3.FILE OPERATIONS:
write c program to implement following FILE operations:...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |