Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help writing text to file (VB2008)
#1
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?
[Image: 6vFJ9.png]


All i have to say is.....

lol


Reply

#2
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
Reply

#3
(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.
[Image: 6vFJ9.png]


All i have to say is.....

lol


Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting text from a website JustDoingThisShit 2 2,852 10-21-2013, 08:00
Last Post: JustDoingThisShit
Wink Preview Black ops 2 - CFG file dump SLiiTH3R 11 19,732 06-09-2013, 16:01
Last Post: dylankrajewski
  [Release] Modern Warfare 3 Fast File Sounds master131 5 18,306 05-21-2013, 16:46
Last Post: ZURA.
Question Help change single file lzma maker to multiple in c# raminr63 1 3,052 05-12-2013, 19:31
Last Post: raminr63
Information How to change text messages in MP (.ff edit) giofrida 5 4,818 05-02-2013, 20:05
Last Post: Pozzuh
  Upload Clipboard Text data to a server DidUknowiPwn 14 8,183 04-13-2013, 14:48
Last Post: SuperNovaAO
  [Release] Black Ops II Fast File Explorer master131 19 26,728 03-28-2013, 16:16
Last Post: kokole
  text book [HARD] Tony. 2 2,684 03-13-2013, 19:39
Last Post: Nekochan
  i want change mod to .iwd file ABDULMAILK 7 6,147 03-10-2013, 05:24
Last Post: DidUknowiPwn
  Black Ops II PC Fast File Key master131 19 18,423 12-08-2012, 13:53
Last Post: Gagarin

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.