2 Replies - 3084 Views - Last Post: 23 February 2011 - 07:33 PM Rate Topic: -----

#1 myhaksown   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 07-January 09

Working with a text file inside my project

Posted 22 February 2011 - 02:32 PM

I have no code specifically for this part of my project just saying this ahead of time. I have not used text files that are inside my project but I want to be able to open the file when I load my form and save it when I close my form. I know how to save manualy and same with opening but that defeats the purpose this has to do as much as possible on its own. All I have are code from a project I made a while back which was a notepad program-

 Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        Dim alltext As String = "", lineoftext As String = ""
        OpenFileDialog1.Filter = "all files|*.*"
        If OpenFileDialog1.FileName <> "" Then

        End If
            FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
            Do Until EOF(1)
                lineoftext = LineInput(1)
                alltext = alltext & lineoftext & vbCrLf
            RichTextBox1.Text = alltext
        End Try
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        SaveFileDialog1.Filter = "Microsoft Office Word Document |*.doc | All files|*.*"
        If SaveFileDialog1.FileName <> "" Then
            FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output)
            PrintLine(1, RichTextBox1.Text)
        End If
    End Sub

however I need this to all happen on its own and it needs to install these text files with the program hence why they are in with the project there are about 30 text files that will need to be with it so if I can get help with one then I can figure the rest out.

Is This A Good Question/Topic? 0
  • +

Replies To: Working with a text file inside my project

#2 Ionut   User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Working with a text file inside my project

Posted 22 February 2011 - 03:36 PM

You should use Filestream class to do this job. If you have the files in the same directory as the exe file, then you can use hardcoded the names. Or you can use a configuration file(an ini or a XML file) to store the names and load them accordingly. Take a look at the exemple from MSDN(the link I posted) and you should have a place to go.
Was This Post Helpful? 0
  • +
  • -

#3 CheckersW   User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 198
  • Joined: 04-April 09

Re: Working with a text file inside my project

Posted 23 February 2011 - 07:33 PM

I might not properly understand your problem, but maybe you should try to execute the opening and saving code in events that are happening anyway?

If you already know the code you want, chuck it in the events of MainForm_Load and MainForm_FormClosing (where MainForm is the name of the master form of your app) and it'll execute when you open and close the form.

(A little side comment on your code: I find it helps HEAPS to change the name of the controls in your project from the default, like instead of calling it "Richtextbox1" or "Button1" try "MainDocument" or something meaningful; it helps when you're looking through your code for you to understand it, or when you're writing new code so you don't have to remember which textbox is textbox1 etc)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1