| Author |
Making a text editor in VB.net 08 |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
|
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? |
|
| Author |
RE: Making a text editor in VB.net 08 |
p4plus2
Member
Posts: 167
Location:
Joined: 31.03.08 Rank: God |
|
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.onblockedclick(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.
"You can't be something your not,
Be yourself by yourself
Stay away from me" ~Walk, Pantera
"Playing an acoustic guitar is like having sex with your clothes on" ~Dave Mustaine |
|
| Author |
RE: Making a text editor in VB.net 08 |
Orillian
Member

Posts: 68
Location: The Sprawl
Joined: 30.06.09 Rank: Monster |
|
|
No, as far as i can remember you need to use something called IOstream or reader or something like that |
|
| Author |
RE: Making a text editor in VB.net 08 |
s3klyma
Member
Posts: 153
Location:
Joined: 02.12.07 Rank: HBH Guru |
|
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
"Shut the fuck up and quit being a naive fucktard." - Zephyr_Pure
"Oh is that so? Well fuck my porridge, you've convinced me,
everyone's just really mean to you." - COM
|
|
| Author |
RE: Making a text editor in VB.net 08 |
p4plus2
Member
Posts: 167
Location:
Joined: 31.03.08 Rank: God |
|
|
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.
"You can't be something your not,
Be yourself by yourself
Stay away from me" ~Walk, Pantera
"Playing an acoustic guitar is like having sex with your clothes on" ~Dave Mustaine |
|
| Author |
RE: Making a text editor in VB.net 08 |
ION
Member
Posts: 18
Location: Planet ION
Joined: 08.10.08 Rank: Active User |
|
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

Of all of the things I've lost, I miss my mind the most! -Ozzy Osbourne
I live my life a quarter mile at a time -Vin Diesel
You cant live, until you've died! -Nikki Sixx
To be great, is to be misunderstood -Lil Wayne |
|