why does TextBox1 show nothing?

Z

zhang

I want to click a button and TextBox1 show the content of the file "1.txt"

but failed why??

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
FileOpen(1, "c:\1.txt", OpenMode.Binary)
FileGet(1, TextBox1.Text)
FileClose()
'TextBox1.Update()
'TextBox1.Refresh()
Dim mylen As Integer
mylen = TextBox1.TextLength() ' mylen is 0,,,,really strange I
think mylen = len of "1.txt"
End Sub
 
K

kimiraikkonen

I want to click a button and TextBox1 show the content of the file "1.txt"

but failed why??

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
FileOpen(1, "c:\1.txt", OpenMode.Binary)
FileGet(1, TextBox1.Text)
FileClose()
'TextBox1.Update()
'TextBox1.Refresh()
Dim mylen As Integer
mylen = TextBox1.TextLength() ' mylen is 0,,,,really strange I
think mylen = len of "1.txt"
End Sub

Zhang,
To read a textfile you must use StreamReader class.
See definition and samples on MSDN:
http://msdn2.microsoft.com/en-us/library/system.io.streamreader.aspx

Hope this helps,

Onur
 
F

Family Tree Mike

A much simpler code that does work is the following:

Dim mylen As Integer

TextBox1.Text = System.IO.File.ReadAllText("c:\1.txt")
mylen = TextBox1.TextLength ' returns correct information
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top