starcraft Posted July 11, 2003 Posted July 11, 2003 (edited) how to i display a text document inside a window on my program without having the text file be a separet file. what i mean is there a way to have the text file within the program and have it display it some how when called. If u cant have it within the program how do u display the text file from a separet file? Ps. How do i create a text document with variables? like"window1 Title = "windowtitle" and add/subtract/call those variables? Edited July 11, 2003 by starcraft Quote
Leaders dynamic_sysop Posted July 11, 2003 Leaders Posted July 11, 2003 well you can include a textfile in your project , but it will get stored in the program's folder anyway , but here's how to read from a textfile on your HD to a textbox : Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim f As IO.File Dim path As String = "C:\test.txt" If f.Exists(path) Then '/// check if the text file exsists. Dim sRead As IO.StreamReader = New IO.StreamReader(New IO.FileStream(path, IO.FileMode.Open)) While Not sRead.Peek TextBox2.AppendText(sRead.ReadLine & Environment.NewLine) '/// read the text file 1 line at a time , in to a textbox. End While sRead.Close() Else MessageBox.Show("oops check you put the correct file path!") End If End Sub Quote
Leaders dynamic_sysop Posted July 11, 2003 Leaders Posted July 11, 2003 also you can use a richtextbox to open the file with a very small amount of code : Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If IO.File.Exists("C:\test.txt") Then RichTextBox1.LoadFile("C:\test.txt", RichTextBoxStreamType.PlainText) End If End Sub Quote
*Experts* mutant Posted July 11, 2003 *Experts* Posted July 11, 2003 You can embed your text file into the exe, but you will only be able to read the text file, wont be able to write to it. Add the file to your solution, go to your soltuion explorer and click on it once, down in the properties window you should see a Build Action property, set it to Embeded Resource. Now you text file will be compiled into the exe. Then to read it do this: Dim reader As New IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("RootNamespace.FileName.txt")) This will retrieve the file for you to read. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.