Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Making a text editor in VB.net 08


ghost's Avatar
0 0

I want to make a text editor in vb.net, a proper one that lets you save files, but all the examples i have found dont allow you to save, only do pointless stuff like change the colour. Can anyone help?


p4plus2's Avatar
Member
0 0

I don't know vb.net but here how I am guessing you could do it. (pseudo code I think you'll manage translating it)

var textfield = new text();
textfield.display(100, 200);

var save = new button();
save.onclick(savetext());

function savetext()
{
     var file = fopen("file.txt", 'w');
     file.fwrite(textfield.get_text);
     file.close();
}

Not sure how well that can translate to VB.NET but if you can manage it, it will work.


ghost's Avatar
0 0

No, as far as i can remember you need to use something called IOstream or reader or something like that


ghost's Avatar
0 0

Here's how you can create and/or write to a file:

Dim writer As StreamWriter = _ New StreamWriter("filepath") writer.WriteLine(information to be written to file) writer.Close()

Check out http://support.microsoft.com/kb/304427 For file I/O


p4plus2's Avatar
Member
0 0

Orillian wrote: No, as far as i can remember you need to use something called IOstream or reader or something like that

Because that is pseudo code, code that represented in generic format so it is simple to translate to another language. In you case VB.NET.


ghost's Avatar
0 0

Here is a piece of code from one of my projects. It still needs to be refined, and I'm sure there are other way to do it, but this is how I did it:

**'The code in the most of this is for a function like "Save As" like in most text editors**
    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
        ' Create a SaveFileDialog to request a path and file name to save to.
        Dim saveFile1 As New SaveFileDialog()
        saveFile1 = SaveFileDialog1

        Dim JDBoolean As Boolean 'JD stands for JohnDoe since its just random, it will be used to declare  if the Form should use the FileSaveDialog's Name
        JDBoolean = False

        ' Initialize the SaveFileDialog to specify the RTF extension for the file.
        saveFile1.DefaultExt = "*.txt"
        saveFile1.Filter = "TXT Files|*.txt"

        ' Determine if the user selected a file name from the saveFileDialog.
        If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
            And (saveFile1.FileName.Length) > 0 Then

            ' Save the contents of the RichTextBox into the file.
            RichTextBox1.SaveFile(saveFile1.FileName, _
                RichTextBoxStreamType.PlainText)
            JDBoolean = True
        Else : MessageBox.Show("You must enter a file name")
            JDBoolean = False
        End If
    End Sub

** 'The next few lines of code are for a button such as "Save" which is found in most text editors**
    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        RichTextBox1.SaveFile("NoteBook.txt")
        'Using SaveFile Method to save text in a rich textbox to hard disk
    End Sub

Hope this helps