Click here to Skip to main content
15,896,726 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: append line number to a text file Pin
Christian Graus9-Sep-09 14:20
protectorChristian Graus9-Sep-09 14:20 
GeneralRe: append line number to a text file Pin
cjdc9-Sep-09 14:29
cjdc9-Sep-09 14:29 
GeneralRe: append line number to a text file Pin
Christian Graus9-Sep-09 14:48
protectorChristian Graus9-Sep-09 14:48 
GeneralRe: append line number to a text file Pin
cjdc9-Sep-09 14:57
cjdc9-Sep-09 14:57 
GeneralRe: append line number to a text file Pin
Christian Graus9-Sep-09 15:05
protectorChristian Graus9-Sep-09 15:05 
AnswerRe: append line number to a text file Pin
Luc Pattyn9-Sep-09 15:21
sitebuilderLuc Pattyn9-Sep-09 15:21 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 7:03
cjdc10-Sep-09 7:03 
GeneralRe: append line number to a text file Pin
Luc Pattyn10-Sep-09 7:12
sitebuilderLuc Pattyn10-Sep-09 7:12 
Hi,

I missed the fact the file could preexist. And yes my code increments the lines generated, however it starts at 1.

if you need to append to an existing file, you have to figure the number of lines present; there are two rather safe ways to do that:
1. read through the entire file, line by line, and count them.
2. read through the entire file, keep the last line, isolate the line number and parse it.

Other ways would include:
3. keep a copy of the last line number somewhere (in registry, in another file, ...)
4. not to use line numbers, use something else than increases all the time (but not by 1), example:
the number yyyyMMddHHmmss containing numeric parts of date and time.

Whatever you do with files, chances are it will fail if and when your app is running more than once at a time on a single computer. And also when it runs on several machines.

The solution, if relevant, is to use a database, where each app would add records to a table, with one of the fields made a primary key, unique and auto-incrementing.

Smile | :)

Luc Pattyn

Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


AnswerRe: append line number to a text file Pin
Hurricane300010-Sep-09 8:12
Hurricane300010-Sep-09 8:12 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 9:09
cjdc10-Sep-09 9:09 
GeneralRe: append line number to a text file Pin
Hurricane300010-Sep-09 9:30
Hurricane300010-Sep-09 9:30 
GeneralRe: append line number to a text file [modified] Pin
cjdc10-Sep-09 10:05
cjdc10-Sep-09 10:05 
GeneralRe: append line number to a text file Pin
Hurricane300010-Sep-09 10:33
Hurricane300010-Sep-09 10:33 
GeneralRe: append line number to a text file Pin
cjdc10-Sep-09 10:49
cjdc10-Sep-09 10:49 
AnswerRe: append line number to a text file Pin
Hurricane300011-Sep-09 4:54
Hurricane300011-Sep-09 4:54 
GeneralRe: append line number to a text file Solved Pin
cjdc14-Sep-09 0:25
cjdc14-Sep-09 0:25 
Questioncomputer to computer communication event Pin
computbill9-Sep-09 13:09
computbill9-Sep-09 13:09 
AnswerRe: computer to computer communication event Pin
Christian Graus9-Sep-09 13:52
protectorChristian Graus9-Sep-09 13:52 
QuestionClass not registered Pin
RossouwDB9-Sep-09 9:01
RossouwDB9-Sep-09 9:01 
AnswerRe: Class not registered Pin
Christian Graus9-Sep-09 9:22
protectorChristian Graus9-Sep-09 9:22 
GeneralRe: Class not registered Pin
RossouwDB9-Sep-09 10:44
RossouwDB9-Sep-09 10:44 
GeneralRe: Class not registered Pin
Christian Graus9-Sep-09 11:20
protectorChristian Graus9-Sep-09 11:20 
GeneralRe: Class not registered Pin
RossouwDB10-Sep-09 5:01
RossouwDB10-Sep-09 5:01 
GeneralRe: Class not registered Pin
RossouwDB12-Sep-09 5:08
RossouwDB12-Sep-09 5:08 
QuestionSuspendLayout, changing Width property and ResumeLayout(True) Pin
EliottA9-Sep-09 7:46
EliottA9-Sep-09 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.