473,412 Members | 4,196 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,412 software developers and data experts.

Last line of sequential access file

I am writing an order number to a txt file.
Each new order takes the order number form the txt file, and apprends by 1 to create the new order number.
However I cant seem to find how to read the last line of the txt file, so I do not get duplicate order numbers?

for example
My text file has the following order numbers:

3403
3404


My code for the text file is as follows

Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim orderNumStreamReader As IO.StreamReader
  3.         Dim orderNumStreamWriter As IO.StreamWriter
  4.         Dim orderNum As Integer
  5.         Dim newOrderNum As Integer
  6.  
  7.  
  8.  
  9.  
  10.         If IO.File.Exists("OrderNum.txt") Then
  11.  
  12.             orderNumStreamReader = IO.File.OpenText("OrderNum.txt")
  13.         Else
  14.             MessageBox.Show("File Does not Exist", "OrderNumber", MessageBoxButtons.OK, _
  15.                 MessageBoxIcon.Information)
  16.  
  17.         End If
  18.  
  19.  
  20.         orderNum = orderNumStreamReader.ReadLine()
  21.         orderNumStreamReader.Close()
  22.  
  23.  
  24.  
  25.  
  26.  
  27.         newOrderNum = orderNum + 1
  28.  
  29.         If IO.File.Exists("OrderNum.txt") Then
  30.  
  31.             orderNumStreamWriter = IO.File.AppendText("OrderNum.txt")
  32.         Else
  33.             MessageBox.Show("File Does not Exist", "OrderNumber", MessageBoxButtons.OK, _
  34.                 MessageBoxIcon.Information)
  35.  
  36.         End If
  37.  
  38.  
  39.         orderNumStreamWriter.WriteLine(newOrderNum)
  40.  
  41.  
  42.         orderNumStreamWriter.Close()
  43.  
  44.  

Now when I run my app, it reads the first line of the order number and appends that, giving me duplicate order numbers.
Apr 1 '07 #1
1 1186
kenobewan
4,871 Expert 4TB
I wonder if this would be better done using xml. If you have a database, you could also update the xml to the database.
Apr 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
2
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to keep my numbers for transactions sequential. I clear my monthly transactions each month and store them in a general transactions...
2
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
3
by: Mark | last post by:
I'm using ASP.Net to accress a database, what I need to do is get the fields out of the very last record in the db. How do I do this? Actually I'm after the primary key, titled 'AdID' it'll tell...
3
by: kd | last post by:
Hi All, I have a .txt file, whose contents need to be read and processed. Which among the following is the best way to do it? - Using Sequential file access functions (FileOpen, LineInput,...
17
by: michel.ank | last post by:
Hi, I'm using the class PrintLines and my last record of page aren't with the borders. Somebody can help me? Thanks,
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.