Alrighty here's my deal, I used this code to enable my program to save...
I'm making this for all of you to use, please get the simple beta program I've made so far from http://www.johnplaird.com on the upper left hand corner is a download link called ("VB Pad"), anyway here's the problem...
' from tool box get a save dialog form to put on your form, or this wont work.
' The code private sub is automatically loaded.
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
' this is what you need
Try
My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
Me.RichTextBox1.Text & vbCrLf, False)
My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, _
Me.RichTextBox1.Text & vbCrLf, True)
Catch fileexception As Exception
Throw fileexception
End Try
' This is the code You will use on the save button.
Me.SaveFileDialog1.ShowDialog()
The problem here is, when I go to save I can save, but I can't select what type of text file this is, then...
I need my program to load and this is what I tried...
I am getting errors, and would like a little code, please...
try
My.computer.filesystem.writealltext
(me.openfiledialog1.filename, _
me.richtextbox1.text & vbcrlf, true)
catch fileexception as exception
throw fileexception
end try
' the openfiledialog thing
me.openfiledialog1.showdialog()

shakalama thanks bud, one more question though, sorry
Suketu
hi,
as what Reneec said what this vbcrlf for you can do something like this in your save button click event handler
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
'show dialog for user to select where s/he want to save the xml file
Dim MySaveDialog As New SaveFileDialog
MySaveDialog.Filter = "RichTextFormat |*.rtf|text|*.txt"
MySaveDialog.Title = "Save File"
Dim result As DialogResult = MySaveDialog.ShowDialog()
'make sure that user hit okbutton and the dataset is not empty
If Not result = Windows.Forms.DialogResult.Cancel Then
Try
RichTextBox1.SaveFile(MySaveDialog.FileName)
Catch ex As Exception
'throw a message if something wrong happend
MessageBox.Show("A Problem occured during saved" & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
in your load button you can use something like this
try
Dim MyOpenDialog As New OpenFileDialog
MyOpenDialog.Filter = "RichtextFormat |*.rtf"
MyOpenDialog.Title = "load"
Dim result As DialogResult = MyOpenDialog.ShowDialog()
If Not result = Windows.Forms.DialogResult.Cancel Then
RichTextBox1.LoadFile(MyopenfileDialog.filename)
End If
Catch ex As Exception
Throw ex
End Try
hope this helps
THHNO
Discoman
Eddie Deyo
What is the CRLF in the open statement for
Chandra B
hi,
its normaly to happen because you have open finle dialog in your form so one it open your dialog that you add to the form and other one it open the dialog in code , remove the open file dialog from your form tray and just move the code under toolstrip sub and it will work fine
hope this helps
RonDesta
Ok, so It works now all that's left is some fine tuning, I used the code you gave me and made the necessary modifications yet it prompts for save and load twice the first time it doesn't include the text file type as in my previous post, but in the second one it does, below I'll post what I've done and leave out everything but the events themselves. Anyway if you downloaded it you'll notice that I set the opacity to a slightly transparent state, this is to helpful when coding wink wink. I really don't want to go any lower, You wouldn't be able to see it I'll include the second version on my website soon.
E-mail junfanjohn@yahoo.com, or john@johnplaird.com
Web http://www.johnplaird.com
' This is my save event
' Its's working like this, but as I said it has to save, or load twice. I'm afraid to play
' around with it too much because it is working lol
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim MySaveDialog1 As New SaveFileDialog
MySaveDialog1.Filter = "RichTextFormat|*.rtf|text|*.txt"
MySaveDialog1.Title = "Save File"
Dim result As DialogResult = MySaveDialog1.ShowDialog()
'make sure that user hit ok button and the dataset is not empty
If Not result = Windows.Forms.DialogResult.Cancel Then
Try
RichTextBox1.SaveFile(MySaveDialog1.FileName)
Catch ex As Exception
'throw a message if something wrong happend
MessageBox.Show("Warning, save was not processed!" & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
' Now for the load event...
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Try
Dim MyOpenfileDialog1 As New OpenFileDialog
MyOpenfileDialog1.Filter = "RichtextFormat |*.rtf"
MyOpenfileDialog1.Title = "load"
Dim result As DialogResult = MyOpenfileDialog1.ShowDialog()
If Not result = Windows.Forms.DialogResult.Cancel Then
RichTextBox1.LoadFile(MyopenfileDialog1.filename)
End If
Catch ex As Exception
Throw ex
End Try
' I'm using the following code to acces it from opendialog
Private Sub LoadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadToolStripMenuItem.Click
Me.OpenFileDialog1.ShowDialog()
bill perlman
Hmm, I was told I needed it like that, I'm really not sure. It didn't copy right any way...
I can't wait till I get payed...
lol I need that book till then can ya help me
E-mail is either john@johnplaird.com, or junfanjohn@yahoo.com
Anything that will get this to save and load properly, I think this guy added, or left something out of his examples because, well here http://www.johnplaird.com
the link in the top left VB Pad is my prog, try saving you'll notice there is no option to select what type of file to save as and as far as loading, well quite frankly bud, I'm lost. I've seen 4 different examples and this is the closest I've come...
Thanks!