By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Saving user prefernces ( slider . check boxes... )

P: n/a
Hello,

I want to save the position of all the controls on my form. I would like to
write them out to a preference file.

I have done this in DOS BASIC like this:

TO WRITE the preference
open "c:\preferences.txt" for input as #1
input #1 ,a,b,c
close #1

TO READ the preferences
open "c:\preferences.txt" for output as #1
write #1,a,b,c
c lose #1

What are the VB.NET commands to do this ?
Thanks
Dan
Nov 20 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Hi try This,

Dim c As Control
Dim sw As StreamWriter = File.CreateText("C:\PREF.TXT")

For Each c In Me.Controls
sw.WriteLine(c.Name & ":" & c.Location.ToString())
Next

sw.Close()

Produces something like this.

Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}

Regards - OHM

Dan DeConinck wrote:
Hello,

I want to save the position of all the controls on my form. I would
like to write them out to a preference file.

I have done this in DOS BASIC like this:

TO WRITE the preference
open "c:\preferences.txt" for input as #1
input #1 ,a,b,c
close #1

TO READ the preferences
open "c:\preferences.txt" for output as #1
write #1,a,b,c
c lose #1

What are the VB.NET commands to do this ?
Thanks
Dan


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #2

P: n/a
Hi,

http://msdn.microsoft.com/library/de...et02122002.asp

http://msdn.microsoft.com/library/de...et07082003.asp

Ken
----------------
"Dan DeConinck" <pi********@sympatico.ca> wrote in message
news:m8********************@news20.bellglobal.com. ..
Hello,

I want to save the position of all the controls on my form. I would like
to
write them out to a preference file.

I have done this in DOS BASIC like this:

TO WRITE the preference
open "c:\preferences.txt" for input as #1
input #1 ,a,b,c
close #1

TO READ the preferences
open "c:\preferences.txt" for output as #1
write #1,a,b,c
c lose #1

What are the VB.NET commands to do this ?
Thanks
Dan

Nov 20 '05 #3

P: n/a
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
Produces something like this.

Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}


And how to read this data?

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
Your such a smart*ss sometimes Herfreid, this is just an example, he can CSV
it or something

:)

OHM

Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
Produces something like this.

Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}


And how to read this data?

;-)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #5

P: n/a
Cor
Hi OHM,

There was I time that I had fun prickling Herfried with that kind of answers
he did do to you. I stopped with it, I thought in the time of the Fergus <->
Herfried battle.

What do you think if I start it again a while and then we do it together
(Armin does it still sometimes)?

Cor
Nov 20 '05 #6

P: n/a
OK, why not, its about time that someone did this :), but dont tell anyone
as I dont want them to know OK!

:)

Regards - OHM

Cor wrote:
Hi OHM,

There was I time that I had fun prickling Herfried with that kind of
answers he did do to you. I stopped with it, I thought in the time of
the Fergus <-> Herfried battle.

What do you think if I start it again a while and then we do it
together (Armin does it still sometimes)?

Cor


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #7

P: n/a
With some embarrasement, I have to admit I was thinking of asking the same
question, but not with any smartss tendency :-) so let me phrase it a
little differently...

I'm still kinda new to programming, and I am designing a new CF project
where I want to add standard controls at runtime, using some type of file
to store the control(s) names, types, location, content (comboboxes,
textboxes), state (radiobuttons, checkboxes), etc.

Users may edit these through my program, so when the program closes, I'll
probably update the file if needed.

The OP asked (more specifically) about writing a preference file; is this
the best approach for storing and uploading control info to be used at
runtime, or are there better built-in functions that I don't know about? Or
are there other (easier) ways to do the same, including possibly saving an
XML file with the same information? I assume I would be looking at the
form.load area of the program to open the file and pull in the information,
and use it to create the controls...

Even giving me an idea of where to look in the VS helpfile (VB.net) would
be great, I simply don't know enough yet to "know what I don't know"

Humbly,
Keith
One Handed Man [ OHM# ] <O_H_M{at}BTInternet{dot}com> wrote in article
<OW**************@TK2MSFTNGP09.phx.gbl>...
Your such a smart*ss sometimes Herfreid, this is just an example, he can CSV it or something

:)

OHM

Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
Produces something like this.

Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}


And how to read this data?

;-)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #8

P: n/a
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
Your such a smart*ss sometimes Herfreid, this is just an example, he can CSV
it or something


I included a ";-)".

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9

P: n/a
Cor
Hi Keith,

I was also looking at this question but the OP did ask it in a very
specific way, which I did not know how to give an answer on but OHM did.

I saw that Herfried had also a question about this, but I think there is a
better approach.

If that does not answer the question from Herfried I will look if I can help
him with his problem how to read such a file.

To give you a more direct answer, the most simple way to save this settings
is in the registry or in an XML file.

Although it looks difficult a dataset is very simple to make (I did give a
lot of samples the last days with it in this newsgroup but if you need it I
can do it again).

That dataset you can easely writen with mydatset.writexml(mypath) and read
with mydataset.readxml(mypath)

If hope this helps, and if not feel free to ask?

Cor
Nov 20 '05 #10

P: n/a
Ken gave this URL which has a discussion on saving configuration data. by
Rocky Lochta or whatever his name is. Basically, the recommendations are use
the registry, XML or some preference file based on the current user.

This is the second time I have answered exactly what the poster asked for
and either got flamed for it or found that the OP wanted something different
entirely. Maybe Im just getting tired.

Regards - OHM
Keith R wrote:
With some embarrasement, I have to admit I was thinking of asking the
same question, but not with any smartss tendency :-) so let me phrase
it a little differently...

I'm still kinda new to programming, and I am designing a new CF
project where I want to add standard controls at runtime, using some
type of file to store the control(s) names, types, location, content
(comboboxes, textboxes), state (radiobuttons, checkboxes), etc.

Users may edit these through my program, so when the program closes,
I'll probably update the file if needed.

The OP asked (more specifically) about writing a preference file; is
this the best approach for storing and uploading control info to be
used at runtime, or are there better built-in functions that I don't
know about? Or are there other (easier) ways to do the same,
including possibly saving an XML file with the same information? I
assume I would be looking at the form.load area of the program to
open the file and pull in the information, and use it to create the
controls...

Even giving me an idea of where to look in the VS helpfile (VB.net)
would be great, I simply don't know enough yet to "know what I don't
know"

Humbly,
Keith
One Handed Man [ OHM# ] <O_H_M{at}BTInternet{dot}com> wrote in article
<OW**************@TK2MSFTNGP09.phx.gbl>...
Your such a smart*ss sometimes Herfreid, this is just an example, he
can CSV it or something

:)

OHM

Herfried K. Wagner [MVP] wrote:
* "One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> scripsit:
Produces something like this.

Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}

And how to read this data?

;-)


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #11

P: n/a
Cor
Hi Herfried,
Button1:{X=56,Y=56}
RadioButton1:{X=176,Y=240}
CheckBox1:{X=88,Y=184}
TextBox1:{X=72,Y=128}


And how to read this data?


I know that when I have a question I never get an answer from you.

But I never answer bad with bad, and maybe I thought Herfried needs this
question for his studie where he is so busy with at the moment, so I made
an sample for you.

Look to it because I am almost sure you can learn something from it.

I hope it helps?

Cor

\\\
Public Module Main
Sub main()
Dim HKWstring() As String = {"Button1:{X=56,Y=56}",
"RadioButton1:{X=176,Y=240}", _
"CheckBox1:{X=88,Y=184}", "TextBox1:{X=72,Y=128}"}
'Herfried to make the sample simple for you I have first made an
array of strings
Dim sw As New IO.StreamWriter("C:\Hkw.txt")
For i As Integer = 0 To HKWstring.Length - 1
'For is another word as "during" however in Cobol it was
perform,
'I do not know if it is, but I see it always as an abbreviation
from that.

'The procedure has to be performed until i is equal to the
arraylength - 1
'maybe a little bit strange for you but an index starts on 0.

'I know you find it now normal that it is 1 and that would be
more normal,
'but this is an old habbit in programming.

sw.WriteLine(HKWstring(i))

'I use i as an index
'every time in a perform loop will the index set up by 1
Next
'the array will be written
sw.Flush()
'this flushes the buffer
sw.Close()
'the file will be given free to read

'Now the file is written we can start with your question how to read
this
Dim sr As New IO.StreamReader("C:\Hkw.txt")
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
line = sr.ReadLine()
Do Until line Is Nothing
' I find this the nicest method
' Is nothing means that the line not exist
' if it was empty it had been = nothing or like others do
' = "", however than it is still a line (a string of zero
characters)
' placed on an existing virtual memory adres

MessageBox.Show(line)
' I placed this so that you can real check that it is been read
line = sr.ReadLine()
Loop
sr.Close()
End Sub

End Module
////


Nov 20 '05 #12

P: n/a
Cor
Hi Herfried,

It was at bottom line and it did cost me to much time that I did not want
that you would not read it.

:-))

Cor
Nov 20 '05 #13

P: n/a
* "Cor" <no*@non.com> scripsit:
It was at bottom line and it did cost me to much time that I did not want
that you would not read it.


I read your post. Very interesing, indeed!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #14

P: n/a
Cor
Not intresting (the perform is maybe for you) only written for fun (but not
wrong) because you made that answer to OHM.

Cor
Nov 20 '05 #15

P: n/a
> Your such a smart*ss sometimes Herfreid, this is just an example, he can
CSV
it or something


Oh boy........hang on everybody.
Nov 20 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.