Home All Groups Group Topic Archive Search About

Help reading simple text file

Author
24 Nov 2006 5:47 PM
Marc
HI,

I have this simple code below that writes my forms buttons name and
location to a text file.

What I am really struggling with is the code to read the information
back in form the text file and create and position a new button based
on the information.

Any Ideas?

        Dim TW As System.IO.TextWriter
           TW = System.IO.File.CreateText("C:\MyTextFile.txt")
        Dim C As Control
        For Each C In Me.Controls
            If TypeOf C Is Button Then
                TW.WriteLine(C.Text)
                TW.WriteLine(C.Location)
            End If
        Next

Author
24 Nov 2006 6:16 PM
Newbie Coder
Here's the solution:

Imports System.io

' I clicked button 1 & put the following code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim sw As New StreamWriter("C:\MyControlName.txt", False)
        Dim c As Control
        For Each c In Me.Controls
            If TypeOf c Is Button Then
                sw.WriteLine(c.Text)
                sw.WriteLine(c.Location.ToString)
            End If
        Next
        sw.Flush()
        sw.Close()
    End Sub

' Exit the application

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
        Application.Exit()
    End Sub

=================

Sample application attached

I hope this helps,

Newbie Coder


Show quoteHide quote
"Marc" <marc_cro***@hotmail.com> wrote in message
news:1164390428.365453.313110@f16g2000cwb.googlegroups.com...
> HI,
>
> I have this simple code below that writes my forms buttons name and
> location to a text file.
>
> What I am really struggling with is the code to read the information
> back in form the text file and create and position a new button based
> on the information.
>
> Any Ideas?
>
>         Dim TW As System.IO.TextWriter
>            TW = System.IO.File.CreateText("C:\MyTextFile.txt")
>         Dim C As Control
>         For Each C In Me.Controls
>             If TypeOf C Is Button Then
>                 TW.WriteLine(C.Text)
>                 TW.WriteLine(C.Location)
>             End If
>         Next
>

[attached file: Control Names (Text File).zip]
Author
25 Nov 2006 10:08 AM
Cor Ligthert [MVP]
Marc,

Try to serialize your buttons, I have read this in past as original from Tom
Shelton in this newsgroup.
http://www.vb-tips.com/dbPages.aspx?ID=7ffd296f-9e81-47e6-88dc-61641f5c8d9d

And don't forget to do this first with your buttons as he write here.
http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/e236fbe04dc0d2aa?hl=en&

:-)

Cor

Show quoteHide quote
"Marc" <marc_cro***@hotmail.com> schreef in bericht
news:1164390428.365453.313110@f16g2000cwb.googlegroups.com...
> HI,
>
> I have this simple code below that writes my forms buttons name and
> location to a text file.
>
> What I am really struggling with is the code to read the information
> back in form the text file and create and position a new button based
> on the information.
>
> Any Ideas?
>
>        Dim TW As System.IO.TextWriter
>           TW = System.IO.File.CreateText("C:\MyTextFile.txt")
>        Dim C As Control
>        For Each C In Me.Controls
>            If TypeOf C Is Button Then
>                TW.WriteLine(C.Text)
>                TW.WriteLine(C.Location)
>            End If
>        Next
>