Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Vb .net .dat file probelm

  • 09-03-2006 12:43pm
    #1
    Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭


    im able to write to the .dat file but if i go to add another line it just over writes the fist line so it will only ever have one line in the .dat file, how do i get app to move to the end of file and then add the new line to the .dat file?
    Private Sub cmdSaveClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveClient.Click
    Dim Main As New frmMain
    Dim str As String = ""
    Dim loc As String = "e:\client.dat"
    Dim binWriter As New IO.BinaryWriter(IO.File.OpenWrite(loc))
    If (txtNewClientName.Text <> " ") And (txtNewClientSource.Text <> " ") Then
    MsgBox("Make sure all fields have been filled.", vbExclamation, "Warning")
    Else
    binWriter.Write(txtNewClientName.Text)
    binWriter.Close()
    Me.Hide()
    Main.Show()
    End If
    End Sub


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    isn't there an append mode for appending to a file?


  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    not sure, i'll look into it now, thanks.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Yeah...either open for append (instead of for write), or don't open/close the file on every click, but rather open it (on first click / on form load / ???) and then keep it open until the form unloads or some other 'single occurrence' event.

    The latter (keep-open) approach is often not the ideal, for a number of reasons, but it is an option to consider. Append is more likely to be your friend though.

    jc


  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    do u mean like:
    binWriter.Append(txtNewClientName.Text)

    i tried this but append is not an option for the Binary writer, its saying this are the only ones u can use:
    binWriter.

    options:
    BaseStream
    Close
    Flush
    GetType
    Null
    Seek
    Write


  • Moderators, Science, Health & Environment Moderators Posts: 9,035 Mod ✭✭✭✭mewso


    Something like this might work:-
    Dim loc As String = "e:\client.dat"
    Dim fs As New IO.FileStream(loc, IO.FileMode.Append)
    Dim binWriter As New IO.BinaryWriter(fs)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey




  • Registered Users, Registered Users 2 Posts: 1,987 ✭✭✭Ziycon


    thanks for everyones help, i got the reading and writing working to a .dat file!

    One last question, i know the vbNewLine moves the curstor to thxt line, is there a way when you delete a row to move up one line?


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Binary files don't really have the same concept of 'lines' that text files would, they're just a stream of data you can probably use 'seek' to go back to a certain point, but you'd have to figure out what point yourself.

    Looking at the data you're putting out, it may make more sense for you to use a text file instead of a binary one (or maybe even XML ?). On the other hand I don't think text files support seek, to delete a line you have to read all lines up to that point, empty the whole file and write them back out again.

    Maybe I'm wrong on that, I'm sure someone can correct me if so.


Advertisement