|
-
Aug 23rd, 2005, 12:24 PM
#1
Thread Starter
Fanatic Member
Read From txt file with VB.NET? What's different?
VB.NET is not liking my code to open a text file for read access. I'm trying to populate a listbox with the contents of a text file, but .NET does not recognize the following code:
Code:
Dim strFile As String
strFile = "\support files\chronill.dat"
Open strFile for input as #1
What is different in VB.NET from 6.0 as far as this goes?
-
Aug 23rd, 2005, 12:29 PM
#2
Re: Read From txt file with VB.NET? What's different?
See the System.IO namespaces it contains all the classes you need...
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Aug 23rd, 2005, 12:32 PM
#3
Re: Read From txt file with VB.NET? What's different?
You need to use a streamreader to read from a file.
VB Code:
Imports System.IO
Private Sub btnReadFromFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadFromFile.Click
Dim myStreamReader As StreamReader
myStreamReader = File.OpenText(txtFileName.Text)
Me.txtFileText.Text = myStreamReader.ReadToEnd()
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 23rd, 2005, 12:33 PM
#4
Re: Read From txt file with VB.NET? What's different?
In .NET there is a totaly new way to read from file, StreamReader
VB Code:
Dim AReadedLine As String ' The buffer string that will contain the strings read
Dim MyStreamReader As System.IO.StreamReader = New System.IO.StreamReader("MyFileName") ' Open the file
AReadedLine = MyStreamReader.ReadLine() ' Read a line from the file
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|