|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
help readin text fileSo i have a text file where each line represents a button name.
What the code I need to read this file and creatre a new button from each line.. so far I just have code to read the whole file Dim TextFileStream As System.IO.TextReade TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt") Dim MyFileContents As String = TextFileStream.ReadToEnd Here's your solution:
' Import Imports System.io ' Add two buttons & add this code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sr As New StreamReader("C:\ButtonNames.txt") Dim strTemp As String Dim intTop As Integer = 50 Do While sr.Peek > -1 strTemp = sr.ReadLine Dim btn As New Button btn.Name = "btn" & strTemp btn.Text = strTemp btn.Left = 10 btn.Height = 24 btn.Top = intTop Me.Controls.Add(btn) Me.Invalidate() intTop += 50 Loop sr.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Application.Exit() End Sub I created a textfile like so One Two Three Four Have added the project to this post too I hope this helps, Newbie Coder Show quoteHide quote "Marc" <marc_cro***@hotmail.com> wrote in message [attached file: Button Names.zip]news:1164391781.764860.138030@j72g2000cwa.googlegroups.com... > So i have a text file where each line represents a button name. > > What the code I need to read this file and creatre a new button from > each line.. > > > so far I just have code to read the whole file > > > Dim TextFileStream As System.IO.TextReade > TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt") > Dim MyFileContents As String = TextFileStream.ReadToEnd > "Marc" <marc_cro***@hotmail.com> schrieb: Reading a text file line-by-line or blockwise with a progress indicator> So i have a text file where each line represents a button name. > > What the code I need to read this file and creatre a new button from > each line.. <URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Marc wrote:
<snip> > Dim TextFileStream As System.IO.TextReade Cool!> TextFileStream = System.IO.File.OpenText("C:\MyTextFile.txt") > Dim MyFileContents As String = TextFileStream.ReadToEnd You learn a new thing everyday. Having seen System.IO.File.OpenText, I wondered if there was something like 'ReadToEnd'. And so it has: Dim Text As String = System.IO.File.ReadAllText(FileName) or, if you prefer it already split into lines: Dim Lines() As String = System.IO.File.ReadAllLines(FileName) Regards, Branco.
Registry Key Manipulation
Need Help on String.Format() method Books for learning VB.NET Serialization Help!!!!!!!!!! VB 2005 Initialising Toobar Help reading simple text file Needto grab the name and position of all buttons on a form -is this possible? Beginners needs some help in Writing to text file Need help to marshall Win32 DLL call to VB.net Want multiple copies of a DLL to run... |
|||||||||||||||||||||||