473,387 Members | 1,882 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,387 software developers and data experts.

To save Control's Text Proprety

I've a form windows with a lot of textbox controls.
How can I do if I have to save all text proprety of this controls in an
external file, to reload them in future?
Nov 20 '05 #1
3 2125
Hi Stefano,

You can look what an XML dataset can do for you, that is very easy to handle
for this.

If you have more questions how, feel free to ask?

Cor

I've a form windows with a lot of textbox controls.
How can I do if I have to save all text proprety of this controls in an
external file, to reload them in future?

Nov 20 '05 #2
* "Stefano" <st*****************@libero.it> scripsit:
I've a form windows with a lot of textbox controls.
How can I do if I have to save all text proprety of this controls in an
external file, to reload them in future?


<URL:http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet02122002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07082003.asp>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Here let me know if this helps.......did not take to long to do

Type the following into your xml file using what you want for your mail server name. Any future settings you wish to add can be placed by typing another Key Name in just the same manner below the first one called "mailserver"

<?xml version="1.0" encoding="utf-8"?><Section Name="Settings"><Key Name="mailserver" Value="mail.charter.net" /></Section

Private Sub ReadXmlConfig(

Create Xml Document instanc
Dim xmlDoc As XmlDocument = New XmlDocumen

load the file.
xmlDoc.Load(Application.StartupPath & "\settings.xml")

Create an array of key nodes of your xml file. Key nodes are the various elements of the xml file that hold your settings
Dim keyNodeList As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("Key"

create an instance of a single keynode which we need to find the single key we are looking for
Dim keyNode As XmlNod

Now we loop through the nodes looking for the keynode holding our mail server value.
For Each keyNode In keyNodeLis

'Each keynode has attributes that together form a "collection." similar to an array. In this case we are seeking the "name" of the node as its attribute.
Dim attribs As XmlAttributeCollection = keyNode.Attribute

Like we did with the keynodes we create a an instance of a single "attribute" called "Name" in which we can look for our value.
Dim attrib As XmlAttribute = attribs("Name"

We are stating that in this loop if the mail server value is found we want to take the attribute of this keynode which is the mailserver value entered earlier and assign it to the string called "mailserver". Each keynode has attributes that together form a "collection." In this case we are seeking the "name" of the node as its 'attribute.
If attrib.Value = "mailserver" The
mailserversetting = attribs("Value").Value.ToString(
End I
Nex

End Su

6) In the form load event type

ReadXmlConfi
TextBox1.Text = mailserve

7) Build and run your project. You should see your mail server setting you assigned appear in the textbox on form load. After admiring your work, shut down the program

8) Now we will change the value of this key as if the end user wanted to change the name of their mail server. Under the ReadXmlConfig sub place another type the following

Sub EnterUserSettings(

Dim strOldEmailValue As Strin
Tr

Create Xml Document instanc
Dim xmlDoc As XmlDocument = New XmlDocumen
load the file.
xmlDoc.Load(Application.StartupPath & "\settings.xml"

Create an array of key nodes of your xml file. Key nodes are the various elements of the xml file that hold your settings
Dim keyNodeList As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("Key"

create an instance of a single keynode which we need to find the single key we are looking for
Dim keyNode As XmlNod

Now we loop through the nodes looking for the keynode holding our mail server value
For Each keyNode In keyNodeLis
Each keynode has attributes that together form a "collection." similar to an array. In this case we are seeking the "name" of the node as its attribute.
Dim attribs As XmlAttributeCollection = keyNode.Attribute

Like we did with the keynodes we create a an instance of a single "attribute" called "Name" in which we can look for our value.
Dim attrib As XmlAttribute = attribs("Name"

We are stating that in this loop if the mail server value is found we want to take the attribute of this keynode which is the mailserver value entered earlier and assign it to the string called "mailserver". Each keynode has attributes that together form a "collection." In this case we are seeking the "name" of the node as its 'attribute.
If attrib.Value = mailserver The

assigning the old value to a variable - in case the settings change fail
strOldValue = attribs("Value").Value.ToString(

set the new value of this key no
attribs("Value").Value = TextBox1.Tex
End I

save the xml fil
xmlDoc.Save(Application.StartupPath & "\settings.xml"
Nex
letting the user know of the chang
MsgBox("Your mail server is " & chooselocation, MsgBoxStyle.Information
Exit Sub
End If
Catch As System.IO.IOException

if saving the file failed

Select Case MessageBox.Show("There was a problem Saving the file, would you like to try another location?")
Case DialogResult.Ok
Dim od as New OpenFileDialog
od.ShowDialog
Dim FileLocation as String = od.FullName
xmlDoc.Save("Blah Blah Blah)
Case DialogResult.No
MessageBox.Show(ex.Message, "File Not Saved")
' or whatever routine you want.
End Select
MsgBox("SETTING " & mailserversetting.ToUpper & " FAILED" & vbCrLf & ex.ToString)

End Try
Nov 20 '05 #4

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

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
3
by: Maya | last post by:
Hey, there! I'm new to vb.net and it seems I wouldn't be able to solve this without help. I have a pipe delimited file that has to be saved in txt format so it could be accepted by my DTS...
4
by: John | last post by:
Hi, I generate a report in a comma delimited file and give it a name like MyReport.csv . I then set a Hyperlink control to point tp the file HyperLink1.text = "Download"...
2
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi, thanks, mister The code string rutaConfig = tbRutaConfigServicioBase.Text; '// Map to the application configuration file. ExeConfigurationFileMap configFile = New...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.