473,804 Members | 3,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help reading control.locatio n value back form text file

The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
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
TW.Close()
End Sub


Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Dim TextFileStream As System.IO.TextR eader
TextFileStream = System.IO.File. OpenText("C:\My TextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
Me.Controls.Add (test)
test.Text = MyFileContents

test.Location = ??????????????? ??????????????? ??

AddHandler test.MouseDown, AddressOf Me.Thebutton_Mo useDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_Mo useMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_Mo useUp
Me.Controls.Add (test)
MsgBox(MyFileCo ntents)
Loop Until MyFileContents = ""
TextFileStream. Close()
End Sub

Nov 24 '06 #1
13 1986

Marc wrote:
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
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
TW.Close()
End Sub


Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Dim TextFileStream As System.IO.TextR eader
TextFileStream = System.IO.File. OpenText("C:\My TextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
Me.Controls.Add (test)
test.Text = MyFileContents

test.Location = ??????????????? ??????????????? ??

AddHandler test.MouseDown, AddressOf Me.Thebutton_Mo useDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_Mo useMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_Mo useUp
Me.Controls.Add (test)
MsgBox(MyFileCo ntents)
Loop Until MyFileContents = ""
TextFileStream. Close()
End Sub
Marc,

I think a better approach to this would be serialization. Not of the
buttons it self, but of a container that controls the attributes...
something like (assuming 2005 here):

Option Strict On
Option Explicit On

<Serializable() _
Friend Class AttributeContai ner
Public Location As Point
Public Size As Size
Public Text As String

Public Sub New(ByVal Location As Point, ByVal Size As Size, ByVal
Text As String)
Me.Location = Location
Me.Size = Size
Me.Text = Text
End Sub
End Class

this class would hold the button values you wish to persist. Then, to
save the attributes:

' a container
Dim btnList As List(Of AttributeContai ner) = New List(Of
AttributeContai ner)

' grab the attributes
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button Then
btnList.Add(New AttributeContai ner(ctrl.Locati on,
ctrl.Size, ctrl.Text))
End If
Next

' write the list in one chunk
Dim bf As New BinaryFormatter ()
Using writter As FileStream = File.OpenWrite( "myfile.dat ")
bf.Serialize(wr itter, btnList)
End Using

to retrieve would look something like:

Using reader As FileStream = File.OpenRead(" myfile.dat")
Dim bf As New BinaryFormatter
Dim btnAttrs As List(Of AttributeContai ner) =
DirectCast(bf.D eserialize(read er), List(Of AttributeContai ner))

For Each attr As AttributeContai ner In btnAttrs
Dim btn As New Button
With btn
.Location = attr.Location
.Size = attr.Size
.Text = attr.Text
End With
Me.Controls.Add (btn)
Next
End Using

HTH

--
Tom Shelton

Nov 25 '06 #2
Marc,

First set Option Strict On in your program, than have a look at the property
"location".

http://msdn2.microsoft.com/en-gb/lib....location.aspx

You see it are points, so to put it back you need first to set what is
written to points,
probably the top and left property are easier to start with,

Cor
"Marc" <ma*********@ho tmail.comschree f in bericht
news:11******** *************@l 39g2000cwd.goog legroups.com...
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
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
TW.Close()
End Sub


Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Dim TextFileStream As System.IO.TextR eader
TextFileStream = System.IO.File. OpenText("C:\My TextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
Me.Controls.Add (test)
test.Text = MyFileContents

test.Location = ??????????????? ??????????????? ??

AddHandler test.MouseDown, AddressOf Me.Thebutton_Mo useDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_Mo useMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_Mo useUp
Me.Controls.Add (test)
MsgBox(MyFileCo ntents)
Loop Until MyFileContents = ""
TextFileStream. Close()
End Sub

Nov 25 '06 #3
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents

Cor Ligthert [MVP] wrote:
Marc,

First set Option Strict On in your program, than have a look at the property
"location".

http://msdn2.microsoft.com/en-gb/lib....location.aspx

You see it are points, so to put it back you need first to set what is
written to points,
probably the top and left property are easier to start with,

Cor
"Marc" <ma*********@ho tmail.comschree f in bericht
news:11******** *************@l 39g2000cwd.goog legroups.com...
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
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
TW.Close()
End Sub


Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Dim TextFileStream As System.IO.TextR eader
TextFileStream = System.IO.File. OpenText("C:\My TextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
Me.Controls.Add (test)
test.Text = MyFileContents

test.Location = ??????????????? ??????????????? ??

AddHandler test.MouseDown, AddressOf Me.Thebutton_Mo useDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_Mo useMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_Mo useUp
Me.Controls.Add (test)
MsgBox(MyFileCo ntents)
Loop Until MyFileContents = ""
TextFileStream. Close()
End Sub
Nov 25 '06 #4

Marc wrote:
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

By the way, I'm going to second Cor's advice. If you aren't using
turning on Option Strict and Option Explicit, then do so. It will make
your code easier to debug, since many errors will be caught at compile
time, and in many cases make your code run faster.

I will note that there is at least one exception to the Option Strict
On. And that's doing late binding. But, that should be a in a
specific file so and a concious decision.

--
Tom Shelton

Nov 25 '06 #5

Marc wrote:
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents

Well, if you don't want to do seralize (which I can send you a simple
working project if you want), then you will need to parse the contents
of the line to get the values for the x and y. when you write out the
point like this, it will write out something like:

{x=100,y=2}

So, you might want to look into the strings Split method and then
Integer.Parse.

--
Tom Shelton

Nov 25 '06 #6
OK,

Can u send me that serialization code then Tom?

what are the advantage sof serialization? I am planning to allow the
user to save and reload the contents of the txtfile at any time

Tom Shelton wrote:
Marc wrote:
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents


Well, if you don't want to do seralize (which I can send you a simple
working project if you want), then you will need to parse the contents
of the line to get the values for the x and y. when you write out the
point like this, it will write out something like:

{x=100,y=2}

So, you might want to look into the strings Split method and then
Integer.Parse.

--
Tom Shelton
Nov 25 '06 #7
Tom,

I tried to insert your serialization code...

It has a few errors..one is that the type list is not defined (see ???
below) and the other is that file is not declared?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
' a container
Dim btnList As ???List??? (Of AttributeContai ner) = New List(Of
AttributeContai ner)
' grab the attributes
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button Then
btnList.Add(New AttributeContai ner(ctrl.Locati on,
ctrl.Size, ctrl.Text))
End If
Next
' write the list in one chunk
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter()
Using writter As IO.FileStream =
???File???.Open Write("C:myfile .dat")
bf.Serialize(wr itter, btnList)
End Using

End Sub

Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Using reader As IO.FileStream = File.OpenRead(" C:myfile.dat")
Dim bf As New
Runtime.Seriali zation.Formatte rs.Binary.Binar yFormatter
Dim btnAttrs As List(Of AttributeContai ner) =
DirectCast(bf.D eserialize(read er), List(Of
AttributeContai ner))

For Each attr As AttributeContai ner In btnAttr
Dim btn As New Button
With btn
.Location = attr.Location
.Size = attr.Size
.Text = attr.Text
End With
Me.Controls.Add (btn)
Next
End Using
Marc wrote:
OK,

Can u send me that serialization code then Tom?

what are the advantage sof serialization? I am planning to allow the
user to save and reload the contents of the txtfile at any time

Tom Shelton wrote:
Marc wrote:
Thanks guys!
>
I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.
>
So now I have....
>
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
>
>
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?
>
i.e test.location = myfilecontents
>

Well, if you don't want to do seralize (which I can send you a simple
working project if you want), then you will need to parse the contents
of the line to get the values for the x and y. when you write out the
point like this, it will write out something like:

{x=100,y=2}

So, you might want to look into the strings Split method and then
Integer.Parse.

--
Tom Shelton
Nov 25 '06 #8
Marc,

That serialization code is on our webside in the URL I gave you, I
simplified it from a longer one from Tom. Instead of an Arraylist you can
take any object as long as it is serializable.

Cor

"Marc" <ma*********@ho tmail.comschree f in bericht
news:11******** **************@ 14g2000cws.goog legroups.com...
OK,

Can u send me that serialization code then Tom?

what are the advantage sof serialization? I am planning to allow the
user to save and reload the contents of the txtfile at any time

Tom Shelton wrote:
>Marc wrote:
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents


Well, if you don't want to do seralize (which I can send you a simple
working project if you want), then you will need to parse the contents
of the line to get the values for the x and y. when you write out the
point like this, it will write out something like:

{x=100,y=2}

So, you might want to look into the strings Split method and then
Integer.Pars e.

--
Tom Shelton

Nov 25 '06 #9
I see now that I have given that link somewhere else where you have stated
this question.

Cor

"Marc" <ma*********@ho tmail.comschree f in bericht
news:11******** *************@l 12g2000cwl.goog legroups.com...
Thanks guys!

I think I might stick to the way Ive done it as serialization looks a
bit hardcore for me.

So now I have....

MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
test.Text = MyFileContents
MyFileContents = TextFileStream. ReadLine
test.Location = New Point(1, 2)
Me.Controls.Add (test)
Which works fine. However I need a way for the test.location line to
read the string in form my text file? how can I do this?

i.e test.location = myfilecontents

Cor Ligthert [MVP] wrote:
>Marc,

First set Option Strict On in your program, than have a look at the
property
"location".

http://msdn2.microsoft.com/en-gb/lib....location.aspx

You see it are points, so to put it back you need first to set what is
written to points,
probably the top and left property are easier to start with,

Cor
"Marc" <ma*********@ho tmail.comschree f in bericht
news:11******* **************@ l39g2000cwd.goo glegroups.com.. .
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ??????????????? ??????. As it
wont accept a string value?

Private Sub Save_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Save.Click
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
TW.Close()
End Sub


Private Sub Load_Click(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles Load.Click
Dim TextFileStream As System.IO.TextR eader
TextFileStream = System.IO.File. OpenText("C:\My TextFile.txt")
Dim MyFileContents As String
Do
MyFileContents = TextFileStream. ReadLine
Dim test As New Button()
Me.Controls.Add (test)
test.Text = MyFileContents

test.Location = ??????????????? ??????????????? ??

AddHandler test.MouseDown, AddressOf Me.Thebutton_Mo useDown
AddHandler test.MouseMove, AddressOf Me.Thebutton_Mo useMove
AddHandler test.MouseUp, AddressOf Me.Thebutton_Mo useUp
Me.Controls.Add (test)
MsgBox(MyFileCo ntents)
Loop Until MyFileContents = ""
TextFileStream. Close()
End Sub

Nov 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2669
by: Ben | last post by:
The page below isn't picking up details or location. What have I missed? Thanks in advance, Ben ____________________________________________ <?PHP
0
2806
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When the email arrives, it has this information: v_firstname: asdf v_lastname: asdf b_email: asdf@bellsouth.net v_phone: asdf v_cellphone: asdf
2
6488
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
7
1986
by: Trvl Orm | last post by:
I am working with 2 frames, Left and Right and the main code is in the left frame, which has been attached. Can someone please help me with this code. I am new to JavaScript and can't figure it out. What needs to happen is this: On the left frame you should have a series of buttons, which when pushed makes things happen on the right frame.
2
1949
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the aqua buttons, (using just windows forms buttons... Main Form cs file //----------------------------------------------------------------------------------------------------------------------
1
1980
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following statement. Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile) How do I get it to go away when the program exits? Now when I quit the program that I called it form the help file is sill displayed. Is there a way to get a handle...
1
3726
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
53
4762
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating records that have a '99' in them (it is similar to a CSV file). Some of my concerns are:
0
5577
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9130
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.