Results 1 to 5 of 5

Thread: [2008] Saving a file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    21

    [2008] Saving a file

    It's me again, this time I need help about this:
    Code:
    Dim txtBox As String
    
    On Error GoTo handler:
    
    Open (App.Path & "\myfile.ext") For Output As #1
    
            If MsgBox("WARNING: This will overwrite your actual file! Are you sure?", vbOKCancel) = vbCancel Then
                        Exit Sub
            End If
            
            txtBox = txtData.Text
            Print #1, txtBox
            
    Close #1
    
    Exit Sub
    
    handler: txtData.Text = "Error on saving"
    This code (I got it from Pino's signature) saves a file as myfile.ext when I click the button, but it doesn't work for VB 2008. Can someone convert it please? Thanks again.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [2008] Saving a file

    Hey,

    Have a look at this post here.

    Hopefully this should help you out.

    Gary

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2008] Saving a file

    try this. Pino's code was vb6 code.

    vb Code:
    1. If MessageBox.Show("WARNING: This will overwrite your actual file! Are you sure?", "Save?.....", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False) = DialogResult.OK Then
    2.    Dim sw As New IO.StreamWriter(My.Application.Info.DirectoryPath & "\myfile.ext")
    3.    sw.Write(txtData.Text)
    4.    sw.Close()
    5. End If

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    21

    Re: [2008] Saving a file

    Thanks again.

  5. #5
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: [2008] Saving a file

    Quote Originally Posted by TimeCode
    It's me again, this time I need help about this:
    Code:
    Dim txtBox As String
    
    On Error GoTo handler:
    
    Open (App.Path & "\myfile.ext") For Output As #1
    
            If MsgBox("WARNING: This will overwrite your actual file! Are you sure?", vbOKCancel) = vbCancel Then
                        Exit Sub
            End If
            
            txtBox = txtData.Text
            Print #1, txtBox
            
    Close #1
    
    Exit Sub
    
    handler: txtData.Text = "Error on saving"
    This code (I got it from Pino's signature) saves a file as myfile.ext when I click the button, but it doesn't work for VB 2008. Can someone convert it please? Thanks again.
    Pino's code was VB6 as paul noted. I'd also replace the On Error statement since it involves a GoTo and that needs an Exit Sub. I'd rewrite it like this:

    Code:
    Try
        If MessageBox.Show("WARNING: This will overwrite your actual file! Are you sure?", "Save?.....", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False) = DialogResult.OK Then
            Dim sw As New IO.StreamWriter(My.Application.Info.DirectoryPath & "\myfile.ext")
            sw.Write(txtData.Text)
            sw.Close()
        End If 
    Catch
        txtData.Text = "Error on saving"
    End Try
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

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