473,408 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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
15 1486
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
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
* "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
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
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
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
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
* "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
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
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
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
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
* "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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Israel | last post by:
The problem: I want to know, definitively when a slider loses focus after a user has started sliding and hasn't released the mouse yet. It appears that this is captured with the WM_ACTIVATEAPP...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
4
by: bill | last post by:
How can I create a slider control or visual scale control which fires a server-side event when a selection is made? I would appreciate any tips. Thanks Bill
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
1
by: theJonster | last post by:
Hi, I have created a page with a list of items and next to these items are comment boxes and check boxes which were dynamically created like this: check = new CheckBox();...
20
by: fatfatpopo | last post by:
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance // <applet code="ImageSlider" width="400" height="400"></applet> import...
10
by: =?Utf-8?B?VGhyb3dtZSBBIEZyaWdnaW5ib25l?= | last post by:
I apologize if this is in the wrong discussion group. I have a C++ form (VS2003) that includes a couple text boxes and a slider bar. Moving the slider bar changes a picture that is displayed and...
6
by: cmgmyr | last post by:
Hello, I'm trying to figure out how to disable a slider through the onChange function. Here is what I have so far: new Control.Slider('handle','slider', { axis:'horizontal', sliderValue: 1,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.