ItsMods

Full Version: Help writing text to file (VB2008)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
OK..

So i have some textboxes, namely 7 of them, i have managed to get it to write to a word document, but what i want is the text to be written to a word document, but with a name i choose it to be saved as, BUT, i will be saving different names, but all the same file type, so if i want to save a file named text.docx and then save a file named text2.docx

Problem is i can't get it to do that, a save file dialog doesn't work how i want it to, i click save, to save it as a .docx file type, and it closes when i save, so i figured it did, but when i look for the file, it isn't there.

I don't really want to save it from a save file dialog, i want it to save the text written in textbox1.text as the file name AND also inside of the .docx file, as well as the information from the other 6 text.boxes

here is the code for the form containing the text boxes and buttons and so forth
it works, but all it does at the moment is save it into a notepad file -___-

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem. _
        OpenTextFileWriter(mfileName, True)
        file.WriteLine(TextBox1.Text)
        file.WriteLine(TextBox2.Text)
        file.WriteLine(TextBox3.Text)
        file.WriteLine(TextBox4.Text)
        file.WriteLine(TextBox5.Text)
        file.WriteLine(TextBox6.Text)
        file.WriteLine(TextBox7.Text)

        file.Close()


        End



        


    End Sub

Also, i want to make a search function, so it searches a specific folder and reads both title and containing text for a matching value, then displays the file in the program, asking if i want to open it, or do another search?

So....

is it possible, or do i have to take another 6 months to learn C# or C++ and waste valuable time making a program which will pay for my new computer?
Try this (It is converted from c#)
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
    File.Create(mfileName)
    Dim ToWrite As String() = New String(5) {}
    ToWrite(0) = TextBox1.Text
    ToWrite(1) = TextBox2.Text
    ToWrite(2) = TextBox3.Text
    ToWrite(3) = TextBox4.Text
    ToWrite(4) = TextBox5.Text
    ToWrite(5) = TextBox6.Text
    ToWrite(6) = TextBox7.Text
    File.WriteAllLines(mfileName, ToWrite)
End Sub
Also make sure mfileName ends with a .docx extension
(11-05-2012, 11:07)archit Wrote: [ -> ]Try this (It is converted from c#)
Code:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
    File.Create(mfileName)
    Dim ToWrite As String() = New String(5) {}
    ToWrite(0) = TextBox1.Text
    ToWrite(1) = TextBox2.Text
    ToWrite(2) = TextBox3.Text
    ToWrite(3) = TextBox4.Text
    ToWrite(4) = TextBox5.Text
    ToWrite(5) = TextBox6.Text
    ToWrite(6) = TextBox7.Text
    File.WriteAllLines(mfileName, ToWrite)
End Sub
Also make sure mfileName ends with a .docx extension


Y U GOTTA BUMP OLD THREADS FOR!!!

Regardless, thank you anyway, i have started to learn C++ so I am coding the program in that.