rnm89 Posted April 26, 2003 Posted April 26, 2003 Can anyone tell me what's wrong with this code? I keep getting a streamreader error. I have added 'Imports System.IO' at the top of the code to import the streamreader class Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 'read test.txt Dim streamtodisplay As streamreader streamtodisplay = New streamreader("c:\test.txt") TextBox1.Text = streamtodisplay.readtoend streamtodisplay.close() TextBox1.Select(0, 0) End Sub Quote
*Gurus* divil Posted April 26, 2003 *Gurus* Posted April 26, 2003 Add Imports System.IO To the top of that code module. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
rnm89 Posted April 26, 2003 Author Posted April 26, 2003 I added Imports System.IO to the VERY TOP of the code Quote
rnm89 Posted April 26, 2003 Author Posted April 26, 2003 OK, I was able to get it to work by starting a NEW project and reloading the code. I thought however that with this code, once form1 started textbox1.text would be loaded with the data in the test.txt file. That is not happening. I have to click into the textbox1.text box then click on the form, after a few seconds, it loads test.txt Thanks for any help!! Quote
*Experts* jfackler Posted April 26, 2003 *Experts* Posted April 26, 2003 If you want the textbox to fill on page load, move this block of code: Dim streamtodisplay As streamreader streamtodisplay = New streamreader("c:\test.txt") TextBox1.Text = streamtodisplay.readtoend streamtodisplay.close() TextBox1.Select(0, 0) into the formload block. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim streamtodisplay As streamreader streamtodisplay = New streamreader("c:\test.txt") TextBox1.Text = streamtodisplay.readtoend streamtodisplay.close() TextBox1.Select(0, 0) End Sub The text changed sub fires every time a character is added to your text box i.e. if you added the string "a e i o u" it will fire 9 times. Doubt if that's what you want to do. Probably why the delay in the fill of your text box in it's current form. After you click on the text box, then click on your form, thus changing the text in the text box and starting the sub, the textbox.textchanged fires for every character in your test.txt. Jon Quote
Leaders dynamic_sysop Posted June 13, 2003 Leaders Posted June 13, 2003 this is the correct method to open your file and get it to fill your chosen textbox / rtfbox : Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim streamtodisplay As StreamReader = New StreamReader(New FileStream("C:\test.txt", FileMode.Open)) With rtfBox .AppendText(streamtodisplay.ReadToEnd) '/// add the textfile to the box End With streamtodisplay.Close() End Sub 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.