Solved Using text files to create incremental numbers not working

Posted on 2014-04-07
Last Modified: 2014-04-07
I am testingthe function below that I am trying to create incremental invoice numbers with, ie 1,2,3,4 etc but for some reason the results are 1, 49, 54, 54, 54 etc

Sub Test
End Sub

    Function oGet_Invoice_Number() As Long
            Dim oLastInvoiceNumber As Long
            Dim oInvoiceNumber As Long
            If System.IO.Directory.Exists("c:\Program Files\KISS_Accounting") = False Then
                System.IO.Directory.CreateDirectory("c:\Program Files\KISS_Accounting")
            End If
            Dim FILE_NAME As String = "c:\Program Files\KISS_Accounting\Invoice_Number.txt"
            'So first see if text file is there - if not write the initial file with 1 as number
            If System.IO.File.Exists(FILE_NAME) = False Then
                Dim oWriter As New System.IO.StreamWriter(FILE_NAME)
                oGet_Invoice_Number = 1
                Exit Function
                Dim oReader As New System.IO.StreamReader(FILE_NAME)
                Dim oReadLine As String = oReader.Read()
                oLastInvoiceNumber = CLng(oReadLine)
                oInvoiceNumber = oLastInvoiceNumber + 1
                Dim oWriter As New System.IO.StreamWriter(FILE_NAME)
                oGet_Invoice_Number = oInvoiceNumber
            End If
        Catch ex As Exception
        End Try

Open in new window

Question by:murbro
  • 2
LVL 35

Accepted Solution

Kimputer earned 500 total points
ID: 39984360
Change the Read to oReader.ReadLine()

Author Closing Comment

ID: 39984386
Thanks. Well spotted!
LVL 27

Expert Comment

ID: 39984415
Dim oReadLine As String = oReader.ReadLine()

Open in new window

instead of
Dim oReadLine As String = oReader.Read()

Open in new window


Author Comment

ID: 39984427
Hi MacroShadow. Sorry I accepted before seeing your post. Would have split the points

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with error message for ReportViewer in VS2015 4 44
Make all values in arrayist to 23 27
LINQ - C# to VB convertion 12 48
DataGridView Events ? 3 37
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now