Results 1 to 3 of 3

Thread: [RESOLVED] Picking value from Text File and App.Path

  1. #1

    Thread Starter
    Addicted Member rpk_20061975's Avatar
    Join Date
    Jun 2001
    Location
    India
    Posts
    234

    Resolved [RESOLVED] Picking value from Text File and App.Path

    Hi,

    I want my application to store the last Ticket No in a text file and when it starts again, it should pick the last number and increment it by 1 to start again.

    I am not following how to pick the value written in text file, though I attempted as below:

    Code:
        Public Function LoadPNoFromFile()
            Dim fs As IO.FileStream = New IO.FileStream("C:\KTR\KTR\ePermit2\Data\pno.txt", IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
            Dim br As IO.BinaryReader = New IO.BinaryReader(fs)
            Dim bw As IO.BinaryWriter = New IO.BinaryWriter(fs)
            Dim GetNum(1000) As Byte
            Dim myVal As Long
    
            Try
    
                myVal = br.ReadByte
                MsgBox(myVal)
                fs.Close()
    
    
            Catch ex As Exception
    
            End Try
        End Function
    Secondly, how to use App.Path (of VB6) here in the code in the line where the path of the Text File is given.
    Last edited by rpk_20061975; Feb 5th, 2006 at 11:40 AM.

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picking value from Text File and App.Path

    First question - You should check out using streamreader instead of filestream and binaryreader if it's a text file.

    VB Code:
    1. Dim sr As New IO.StreamReader("Mytextfile")
    2. Dim Ticketno as String
    3.  
    4. While Not (sr.Peek() = -1)
    5.    Ticketno = Sr.ReadLine()
    6. End While
    7. SR.Close()
    8. 'This will leave you with ticketno containing the last line of the text file.
    9.  
    10. 'Then to write back the next one.
    11.  
    12. Dim sw As New IO.StreamWriter("MyTextFile", True) 'append is true
    13. Sw.WriteLine(TheNextTicketNumber)
    14. sw.Close()

    And for question two:

    Application.StartupPath

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Addicted Member rpk_20061975's Avatar
    Join Date
    Jun 2001
    Location
    India
    Posts
    234

    Re: Picking value from Text File and App.Path

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width