VB.net Using text files to create incremental numbers not working

Posted on 2014-04-07
Medium Priority
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:Murray Brown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 36

Accepted Solution

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

Author Closing Comment

by:Murray Brown
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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 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