473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Reading and Writing Text Files

Hey all I have this code that reads from one text file writes to
another unless im on a certian line then it writes the new data however
it only seems to do about 40 lines then quits and I cant figure out why
any help would be much apprechiated

1.
Dim line_num As Integer
2.
Dim filename2 As String
3.
Dim csv_text As String
4.
csv_text = companytxt.Text & "," & Nametxt.Text & "," &
addrtxt.Text & "," & citytxt.Text & "," & statetxt.Text & "," &
ziptxt.Text & "," & countrytxt.Text & "," & phonetxt.Text & "," &
faxtxt.Text & "," & celltxt.Text & "," & titletxt.Text & "," &
assistanttxt.Text & "," & urltxt.Text & "," & altcontacttxt.Text & ","
& altphonetxt.Text & "," & altaddrtxt.Text & "," & altcitytxt.Text &
"," & altstatetxt.Text & "," & altziptxt.Text & "," & territorytxt.Text
& "," & mech1serialnum.Text & "," & mech1vacpump.Text & "," &
mech1spindle.Text & "," & mech1vacpumpserialnum.Text & "," &
mech1filterpartnum.Text & "," & mech2serialnum.Text & "," &
mech2vacpump.Text & "," & mech2spindle.Text & "," &
mech2vacpumpserialnum.Text & "," & mech2filterpartnum.Text & "," &
mech3serialnum.Text & "," & mech3vacpump.Text & "," & mech3spindle.Text
& "," & mech3vacpumpserialnum.Text & "," & mech3filterpartnum.Text &
"," & mech4serialnum.Text & "," & mech4vacpump.Text & "," &
mech4spindle.Text & "," & mech4vacpumpserialnum.Text & "," &
mech4filterpartnum.Text & "," & user1txt.Text & "," & user2txt.Text &
"," & user3txt.Text & "," & user4txt.Text & "," & user5txt.Text & "," &
user6txt.Text & "," & user7txt.Text & "," & user8txt.Text & "," &
user9txt.Text & "," & user10txt.Text & "," & user11txt.Text & "," &
user12txt.Text & "," & user13txt.Text & "," & user14txt.Text & "," &
user15txt.Text
5.
filename2 = "C:\Documents and Settings\Brian Bepristis\My
Documents\Visual Studio Projects\Multicamtemp.csv"
6.
Dim filename As String
7.
filename = "C:\Documents and Settings\Brian Bepristis\My
Documents\Visual Studio Projects\Multicamtemp2.csv"
8.
' Create an empty string array to return to caller.
9.
Dim lines() As String = {}
10.

11.
' Check to see if the file exists.
12.
If File.Exists(filename) Then
13.
' Open a stream reader to get the text from the file.
14.
Dim sr As New StreamReader(filename)
15.
' Read all the file text.
16.
Dim fileText As String = sr.ReadToEnd()
17.
' Close the stream reader
18.
sr.Close()
19.

20.
' Split the text into a string array delimited by
Carriage Return/Line Feed.
21.
lines = Split(fileText, vbCrLf)
22.

23.
' Return
24.
Dim fs As New FileStream(filename2, FileMode.Create)
25.
Dim sw As New StreamWriter(fs)
26.

27.
Dim foundBlank As Boolean
28.
For Each line As String In lines
29.
If line.Length > 0 Then
30.
line_num += 1
31.
If line_num = currecord Then
32.
sw.WriteLine(csv_text)
33.
' Reset blank line flag
34.
foundBlank = False
35.
Else
36.
sw.WriteLine(line)
37.
' Reset blank line flag
38.
foundBlank = False
39.
End If
40.
Else
41.
If Not foundBlank Then
42.
' Blank line: write first one
43.
sw.WriteLine(line)
44.
' Set flag to indicate that blank line
was found
45.
foundBlank = True
46.
End If
47.
End If
48.
Next
49.
sw.Close()
50.
fs.Close()
51.
End If
52.
If System.IO.File.Exists(filename2) = True Then
53.
If System.IO.File.Exists(filename) = True Then
54.
System.IO.File.Delete(filename)
55.
End If
56.
System.IO.File.Copy(filename2, filename)
57.
End If

May 11 '06 #1
3 2137
Are you sure you don't have included a chrw(0) value.

After that you cannot see anything anymore.

I hope this helps,

Cor

"bbepristis" <br*************@gmail.com> schreef in bericht
news:11**********************@v46g2000cwv.googlegr oups.com...
Hey all I have this code that reads from one text file writes to
another unless im on a certian line then it writes the new data however
it only seems to do about 40 lines then quits and I cant figure out why
any help would be much apprechiated

1.
Dim line_num As Integer
2.
Dim filename2 As String
3.
Dim csv_text As String
4.
csv_text = companytxt.Text & "," & Nametxt.Text & "," &
addrtxt.Text & "," & citytxt.Text & "," & statetxt.Text & "," &
ziptxt.Text & "," & countrytxt.Text & "," & phonetxt.Text & "," &
faxtxt.Text & "," & celltxt.Text & "," & titletxt.Text & "," &
assistanttxt.Text & "," & urltxt.Text & "," & altcontacttxt.Text & ","
& altphonetxt.Text & "," & altaddrtxt.Text & "," & altcitytxt.Text &
"," & altstatetxt.Text & "," & altziptxt.Text & "," & territorytxt.Text
& "," & mech1serialnum.Text & "," & mech1vacpump.Text & "," &
mech1spindle.Text & "," & mech1vacpumpserialnum.Text & "," &
mech1filterpartnum.Text & "," & mech2serialnum.Text & "," &
mech2vacpump.Text & "," & mech2spindle.Text & "," &
mech2vacpumpserialnum.Text & "," & mech2filterpartnum.Text & "," &
mech3serialnum.Text & "," & mech3vacpump.Text & "," & mech3spindle.Text
& "," & mech3vacpumpserialnum.Text & "," & mech3filterpartnum.Text &
"," & mech4serialnum.Text & "," & mech4vacpump.Text & "," &
mech4spindle.Text & "," & mech4vacpumpserialnum.Text & "," &
mech4filterpartnum.Text & "," & user1txt.Text & "," & user2txt.Text &
"," & user3txt.Text & "," & user4txt.Text & "," & user5txt.Text & "," &
user6txt.Text & "," & user7txt.Text & "," & user8txt.Text & "," &
user9txt.Text & "," & user10txt.Text & "," & user11txt.Text & "," &
user12txt.Text & "," & user13txt.Text & "," & user14txt.Text & "," &
user15txt.Text
5.
filename2 = "C:\Documents and Settings\Brian Bepristis\My
Documents\Visual Studio Projects\Multicamtemp.csv"
6.
Dim filename As String
7.
filename = "C:\Documents and Settings\Brian Bepristis\My
Documents\Visual Studio Projects\Multicamtemp2.csv"
8.
' Create an empty string array to return to caller.
9.
Dim lines() As String = {}
10.

11.
' Check to see if the file exists.
12.
If File.Exists(filename) Then
13.
' Open a stream reader to get the text from the file.
14.
Dim sr As New StreamReader(filename)
15.
' Read all the file text.
16.
Dim fileText As String = sr.ReadToEnd()
17.
' Close the stream reader
18.
sr.Close()
19.

20.
' Split the text into a string array delimited by
Carriage Return/Line Feed.
21.
lines = Split(fileText, vbCrLf)
22.

23.
' Return
24.
Dim fs As New FileStream(filename2, FileMode.Create)
25.
Dim sw As New StreamWriter(fs)
26.

27.
Dim foundBlank As Boolean
28.
For Each line As String In lines
29.
If line.Length > 0 Then
30.
line_num += 1
31.
If line_num = currecord Then
32.
sw.WriteLine(csv_text)
33.
' Reset blank line flag
34.
foundBlank = False
35.
Else
36.
sw.WriteLine(line)
37.
' Reset blank line flag
38.
foundBlank = False
39.
End If
40.
Else
41.
If Not foundBlank Then
42.
' Blank line: write first one
43.
sw.WriteLine(line)
44.
' Set flag to indicate that blank line
was found
45.
foundBlank = True
46.
End If
47.
End If
48.
Next
49.
sw.Close()
50.
fs.Close()
51.
End If
52.
If System.IO.File.Exists(filename2) = True Then
53.
If System.IO.File.Exists(filename) = True Then
54.
System.IO.File.Delete(filename)
55.
End If
56.
System.IO.File.Copy(filename2, filename)
57.
End If

May 11 '06 #2
not sure im new to vb so Im not sure what you mean

May 11 '06 #3
Nevermind figured it out there was some funky charicters in the csv
file stoping it..

Chars were --- NSB@ VL? ---

May 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dunnm | last post by:
This is probably a more appropriate location to post this question. I should have know that since I've found most of the other PHP/PDF information contained in this group. Here's my issue...I...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
7
by: random guy | last post by:
Hi, I'm writing a program which creates an index of text files. For each file it processes, the program records the start and end positions (as returned by tellg()) of sections of interest,...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
1
by: akalmand | last post by:
Hi there, I am writing a code to read some data from the text files. The number of text files is not fixed and could be more that 15. the length of each file is large... close to 100,000 on an...
4
by: pbj2009 | last post by:
Hello all: I'm pretty stumped on this one. I'm not looking for Code, I'm just trying to figure out the best way to start this since I am new to reading and writing from files. I can't figure out...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.