vb.net - Loading text from a file into a textbox -
i'm trying place text text file in textbox, textbox remains blank after code executes. how can fix this?
dim fileno1 integer = freefile() fileopen(fileno1, "c:\users\main computer\desktop\vb test\gyn-obs-d.txt", openmode.input, openaccess.read, openshare.shared) dim y boolean = 0 dim c = 0 textbox1.text = "1" while not eof(fileno1) c += 1 dim txt string = lineinput(fileno1) debug.writeline(txt) dim inputstring string = txt textbox1.text = txt if c = 40 y = 1 exit end if write1(inputstring, y) loop fileclose(fileno1)
edit: added class still wrong
' of course these next 2 @ top imports system imports system.io
class test public shared sub main() try ' create instance of streamreader read file. ' using statement closes streamreader. using sr new streamreader("testfile.txt") dim line string ' read , display lines file until end of ' file reached. line = sr.readline() if not (line nothing) console.writeline(line) end if textbox1.text=line loop until line nothing end using catch e exception ' let user know went wrong. console.writeline("the file not read:") console.writeline(e.message) end try end sub end class
how about
textbox.text = system.io.file.readalltext("c:\users\main computer\desktop\vb test\gyn-obs-d.txt")
if long
textbox.text = system.io.file.readalltext("c:\users\main computer\desktop\vb test\gyn-obs-d.txt").substring(0,1000)
Comments
Post a Comment