Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

[SOLVED] How to save/get parameters from multiple forms inn vb.net (2008)
Started by jurru, Sep 16 2012 08:04 AM
VB.NET file settings in vb;net 2008
9 replies to this topic
#1
Posted 16 September 2012 - 08:04 AM
Does anyone know how to save and get user file settings? I have an application with over four dialog forms. Each form has various controls such as textbox, dropdowns, etc. During runtime, a particular form should be ble to get parametrs from other form controls. When the application is closed, all parametrs should be saved in a user defind path, which can later be opened so that all paralmeter would show un in all control fields of all forms. I tried to look at application settings but have the impression that it is only settings that desn't change at each executions, and it cannot be saved anywhere.
I tried XML. I can save and get parametrs from one form but not betwwen forms, i.e to handle the parametrs of each form, I have to create XML file for each form. If I have several forms, I cannot put all in a single XML?
So, any idea please.
I tried XML. I can save and get parametrs from one form but not betwwen forms, i.e to handle the parametrs of each form, I have to create XML file for each form. If I have several forms, I cannot put all in a single XML?
So, any idea please.
#2
Posted 16 September 2012 - 08:17 AM
What is the problem saving all the parameters for all 4 items in a single XML file?
#3
Posted 16 September 2012 - 08:49 AM
What is the problem saving all the parameters for all 4 items in a single XML file?
Thank you kernelcoder. The following XML works fine to save and get parametrs from one form, say Form1. But it cannot save/get parametrs from another (Form2). For now, both Form1 and Form2 have text fields. My question is, how save/get parametres from all forms into one XML file.
This is the XML file I use per form:
<?xml version="1.0" standalone="yes"?>
<SimSetting xmlns="http://tempuri.org/S...imSetting.xsd">
<basic>
<name>Jhon</name>
<leader>Senior</leader>
<company>XCompany</company>
<buyer>Mr Goody</buyer>
</basic>
</SimSetting>
I do not know if I am clear enough but my idea is to save everything on the program into one XML file to user defined file name and file path. The user can change information on the form and then save them to another file name in his/her prefered path. The user can also open any of the saved files to see the corresponding information on the forms.
#4
Posted 16 September 2012 - 08:54 AM
How about this way? --
<?xml version="1.0" standalone="yes"?> <SimSetting xmlns="http://tempuri.org/S...imSetting.xsd"> <Forms> <Form1> <basic> <name>Jhon</name> <leader>Senior</leader> <company>XCompany</company> <buyer>Mr Goody</buyer> </basic> </Form1> <Form2> <basic> <name>Jhon</name> <leader>Senior</leader> <company>XCompany</company> <buyer>Mr Goody</buyer> </basic> </Form2> <Form3> <basic> <name>Jhon</name> <leader>Senior</leader> <company>XCompany</company> <buyer>Mr Goody</buyer> </basic> </Form3> <Form4> <basic> <name>Jhon</name> <leader>Senior</leader> <company>XCompany</company> <buyer>Mr Goody</buyer> </basic> </Form4> </Forms> </SimSetting>
#5
Posted 16 September 2012 - 09:39 AM
Thanks again, kernelcoder. Thes, the output format is exactly like that BUT how can I (I mean the program) generate the above XML that takes into account each form name to bind the properties within it? Is it in the setting.xsd file? If so, how?
Let me put the codes I am using:
'On Form1, I save the parameters as follows:
Dim fBasic As String = Path.GetDirectoryName(fileName)
Dim xDS As New SimSetting
Dim xRow As SimSetting.basicRow
xRow = xDS.basic.NewbasicRow
xRow.name = TextBox1.Text.Trim()
xRow.leader = TextBox2.Text.Trim()
xRow.company = TextBox3.Text.Trim()
xRow.buyer = TextBox4.Text.Trim()
xDS.basic.AddbasicRow(xRow)
xDS.WriteXml(fBasic, System.Data.XmlWriteMode.IgnoreSchema)
'The I load parameters on Form1_Load as follows:
Dim fBasic As String = Path.GetDirectoryName(fileName)
If New FileInfo(fBasic).Exists Then
Dim xDS As New SimSetting
Dim xRow As SimSetting.basicRow
xDS.ReadXml(fBasic, System.Data.XmlReadMode.IgnoreSchema)
If xDS.basic.Rows.Count > 0 Then
xRow = xDS.basic.Rows.Item(0)
If Not xRow.IsnameNull() Then
TextBox1.Text = xRow.name
End If
If Not xRow.IsleaderNull() Then
TextBox2.Text = xRow.leader
End If
If Not xRow.IscompanyNull() Then
TextBox3.Text = xRow.company
End If
If Not xRow.IsbuyerNull() Then
TextBox3.Text = xRow.buyer
End If
End If
End If
And then, I have still Form2, Form3, with their own settings of parameters. By the way, in form2, form3, form4, thext fields have IDs different from the one showed above (in Form1). For instance, on Form2, I do not have company and buyer name information. Rather I have to handle secific items, type, size, price, etc.
In all, I have to comeup with they type of XML format you showed above. I should be able to save as well as open it. I should also save all those info in a different file name as a backup.
If you understood my problem, is there any easy way to do that. From what I read to hadle such files, XML seems to be the prefered one but couldn't get it xorking. I was using flat text file for each form parametres but it becomes messy when we have several forms.
Let me put the codes I am using:
'On Form1, I save the parameters as follows:
Dim fBasic As String = Path.GetDirectoryName(fileName)
Dim xDS As New SimSetting
Dim xRow As SimSetting.basicRow
xRow = xDS.basic.NewbasicRow
xRow.name = TextBox1.Text.Trim()
xRow.leader = TextBox2.Text.Trim()
xRow.company = TextBox3.Text.Trim()
xRow.buyer = TextBox4.Text.Trim()
xDS.basic.AddbasicRow(xRow)
xDS.WriteXml(fBasic, System.Data.XmlWriteMode.IgnoreSchema)
'The I load parameters on Form1_Load as follows:
Dim fBasic As String = Path.GetDirectoryName(fileName)
If New FileInfo(fBasic).Exists Then
Dim xDS As New SimSetting
Dim xRow As SimSetting.basicRow
xDS.ReadXml(fBasic, System.Data.XmlReadMode.IgnoreSchema)
If xDS.basic.Rows.Count > 0 Then
xRow = xDS.basic.Rows.Item(0)
If Not xRow.IsnameNull() Then
TextBox1.Text = xRow.name
End If
If Not xRow.IsleaderNull() Then
TextBox2.Text = xRow.leader
End If
If Not xRow.IscompanyNull() Then
TextBox3.Text = xRow.company
End If
If Not xRow.IsbuyerNull() Then
TextBox3.Text = xRow.buyer
End If
End If
End If
And then, I have still Form2, Form3, with their own settings of parameters. By the way, in form2, form3, form4, thext fields have IDs different from the one showed above (in Form1). For instance, on Form2, I do not have company and buyer name information. Rather I have to handle secific items, type, size, price, etc.
In all, I have to comeup with they type of XML format you showed above. I should be able to save as well as open it. I should also save all those info in a different file name as a backup.
If you understood my problem, is there any easy way to do that. From what I read to hadle such files, XML seems to be the prefered one but couldn't get it xorking. I was using flat text file for each form parametres but it becomes messy when we have several forms.
#6
Posted 16 September 2012 - 06:11 PM
Well, after doing the change in XML file, you just need to regenerate the XSD from the XML and use it. Find the zip attachment as the XSD file that I generated and used in the following sample code.
Dim fBasic As String = "C:\AppSettings.xml" If System.IO.File.Exists(fBasic) Then Dim xDS As New SimSetting xDS.ReadXml(fBasic, System.Data.XmlReadMode.IgnoreSchema) //Read form1 settings Dim row1 As SimSetting.form1Row If xDS.form1.Rows.Count > 0 Then row1 = xDS.form1.Rows.Item(0) Console.WriteLine(String.Format("Form1 Info# name:{0}, leader:{1}, company:{2}, buyer:{3}", row1.name, row1.leader, row1.company, row1.buyer)) End If //Read form2 settings Dim row2 As SimSetting.form2Row If xDS.form2.Rows.Count > 0 Then row2 = xDS.form2.Rows.Item(0) Console.WriteLine(String.Format("Form2 Info# name:{0}, leader:{1}, price:{2}, size:{3}", row2.name, row2.leader, row2.price, row2.size)) End If End IfAnd, the output of the above code is ---
Form1 Info# name:Jhon, leader:Senior, company:XCompany, buyer:Mr Goody Form2 Info# name:Jhon, leader:Senior, price:100, size:50
Attached Files
#7
Posted 17 September 2012 - 12:34 PM
kernercoder, that is perfect. Just one one minor point, initially I had to place the xml file manually. The code was not able to create it. But once the file is placed manually, things function exactely as I wanted. Thanks a lot!
#8
Posted 17 September 2012 - 09:30 PM
Yes, we need an xml file to create the XSD for the first time but I think the saving code should create a new xml file if it does not exist. The following code creates an XML file --kernercoder, that is perfect. Just one one minor point, initially I had to place the xml file manually. The code was not able to create it. But once the file is placed manually, things function exactely as I wanted. Thanks a lot!
Dim xDS As New SimSetting Dim row1 As SimSetting.form1Row row1 = xDS.form1.Newform1Row() row1.name = "Jhon" row1.company = "RTL" row1.buyer = "Mr Goody" row1.leader = "Senior" xDS.form1.Addform1Row(row1) Dim row2 As SimSetting.form2Row row2 = xDS.form2.Newform2Row() row2.name = "Jhon" row2.leader = "Senior" row2.price = 10 row2.size = 5 xDS.form2.Addform2Row(row2) Dim row3 As SimSetting.form3Row row3 = xDS.form3.Newform3Row() row3.name = "Jhon" row3.company = "RTL" row3.buyer = "Mr Goody" row3.leader = "Senior" xDS.form3.Addform3Row(row3) Dim row4 As SimSetting.form4Row row4 = xDS.form4.Newform4Row() row4.name = "Jhon" row4.company = "RTL" row4.buyer = "Mr Goody" row4.leader = "Senior" xDS.form4.Addform4Row(row4) xDS.WriteXml("c:\\testxml.xml").
And the content of the created XML file is --
<?xml version="1.0" standalone="yes"?> <SimSetting xmlns="http://tempuri.org/S...imSetting.xsd"> <form1> <name>Jhon</name> <leader>Senior</leader> <company>RTL</company> <buyer>Mr Goody</buyer> </form1> <form2> <name>Jhon</name> <leader>Senior</leader> <price>10</price> <size>5</size> </form2> <form3> <name>Jhon</name> <leader>Senior</leader> <company>RTL</company> <buyer>Mr Goody</buyer> </form3> <form4> <name>Jhon</name> <leader>Senior</leader> <company>RTL</company> <buyer>Mr Goody</buyer> </form4> </SimSetting>.
So I think you better use this XML file rather than the older one and regenerate a new XSD file to cope with this new XML format.
#9
Posted 18 September 2012 - 08:39 AM
Everything is perfect. Thanks a lot, kernelcoder !
#10
Posted 18 September 2012 - 08:49 AM
This topic has been marked as SOLVED. If you have a similar question or topic, you can go back to the subforum and start a new topic to continue discussions.
New around here? Click here to register and start participating in under a minute?
Or do a quick search and you may find the answer you're looking for.
Also tagged with one or more of these keywords: VB.NET, file settings in vb;net 2008
Tutorial Forums →
Visual Basic Tutorials →
Visual Basic .NET Tutorial - How to add google maps in a VB programme Part 2/2 - codecall.netStarted by Cobus, 09 Feb 2016 ![]() |
|
![]() |
||
Language Forums →
Visual Basic →
Find & Replace in MenuStripStarted by Gooer, 21 Dec 2015 ![]() |
|
![]() |
||
Language Forums →
Visual Basic →
Program to give sum of all odd and even digitsStarted by Gooer, 09 Dec 2015 ![]() |
|
![]() |
||
Language Forums →
Visual Basic →
DSP (Digital Signal Processing) with VB.NetStarted by LoneRanger, 19 Aug 2015 ![]() |
|
![]() |
||
Language Forums →
Visual Basic →
I want to learn Visual Basic .Net 2013Started by Raja2921, 28 Jul 2015 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download