|
-
Oct 5th, 2008, 01:08 PM
#1
Thread Starter
Junior Member
[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.
-
Oct 5th, 2008, 01:19 PM
#2
Re: [2008] Saving a file
Hey,
Have a look at this post here.
Hopefully this should help you out.
Gary
-
Oct 5th, 2008, 01:24 PM
#3
Re: [2008] Saving a file
try this. Pino's code was vb6 code.
vb Code:
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 5th, 2008, 01:26 PM
#4
Thread Starter
Junior Member
-
Oct 5th, 2008, 01:32 PM
#5
Frenzied Member
Re: [2008] Saving a file
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|