|
-
Jan 19th, 2004, 06:43 AM
#1
Thread Starter
Addicted Member
-
Jan 19th, 2004, 07:05 AM
#2
Sleep mode
Don't use INI . Instead , use XML file Configuration file . It's very easy with less code and overall has more advantages than INI files. Here's an example : http://www.thescarms.com/dotNet/AppSettings.asp
and Don't feel that way , we're here just help each other .
-
Jan 19th, 2004, 08:13 AM
#3
Thread Starter
Addicted Member
Thanks a TON!
Excellent! Pirate. 
Thanks so much for introducing me to XML.
I will try this for sure.
-
Jan 20th, 2004, 12:35 PM
#4
Addicted Member
I took a look at that link and it didnt help 1 bit. I think a ini file is way easier even tho i dont know how to create one. Ini Files are easier to read and just easier to deal with. So can someone point me to a INI file tutorial. Or a better XML tutorial Thanks
Live to love, Not to hate
-
Jan 20th, 2004, 01:17 PM
#5
New Member
I agree with Pirate.
I got all I needed to come to grips with it in the VS .Net help files. I personally use an .xml file as opposed to the app.config. Just a matter of preference.
-
Jan 20th, 2004, 02:52 PM
#6
Sleep mode
Originally posted by AtomSoft
I took a look at that link and it didnt help 1 bit. I think a ini file is way easier even tho i dont know how to create one. Ini Files are easier to read and just easier to deal with. So can someone point me to a INI file tutorial. Or a better XML tutorial Thanks
Well , how about http://www.google.com ?
-
Jan 20th, 2004, 03:09 PM
#7
Member
-
Jan 21st, 2004, 07:44 PM
#8
Addicted Member
for as google. That is my home page. I am a google freak. Google rocks but its tirering searching and searching and etc.. Ok if i ask for hel pwhy do you point me to another place to ask for help. Why not give me a straight link ? do you use google ? if so why not search for me and send me the right link or give me the code yourself?
I am not trying to get you mad but i get tired of replys that dont help. If you are going to reply it should be usefull. Thanks for your time.
Live to love, Not to hate
-
Jan 21st, 2004, 08:16 PM
#9
You don't really need to know much about xml to use an app.config file. You can use one of a couple different methods included in the .NET framework to read them (in the Configuration namespace) and typically you can write them in any text editor or the IDE. Here is a tutorial on the app.config file: http://www.edneeis.com/example.aspx?ID=13 As for writing to config files at runtime there are a number of good classes floating about the net to handle this.
Or the ultimate source for xml is: http://www.w3.org/TR/xpath
Don't disregard it because its from a standards site it has lots of useful information and good xpath examples. XPath is sort of query language for xml.
-
Jan 21st, 2004, 10:26 PM
#10
Thread Starter
Addicted Member
Much appreciated your sample Code Edneeis. 
I tested it and it works perfectly for both saving and retrieving values.
I was able to retrive the value from a Config file using Pirate's link to TheScarms Visual Basic.NET Code Library.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim aConfig As Configuration.ConfigurationSettings
Dim CDSize As String = aConfig.AppSettings("CDSize")
Dim NumberOfCDs As String = aConfig.AppSettings("NumberOfCDs")
TextBox1.Text = CDSize
TextBox2.Text = NumberOfCDs
End Sub
However I wasn't smart enough to save new values back to the Config file.
I tried:
VB Code:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim aConfig As Configuration.ConfigurationSettings
Dim CDSize As String = aConfig.AppSettings("CDSize")
Dim NumberOfCDs As String = aConfig.AppSettings("NumberOfCDs")
CDSize = TextBox1.Text
NumberOfCDs = TextBox2.Text
End Sub
Although Edneeis works nicely for me, I would be still interested to know how to save new values to the config according to Pirate's Link.
Thank you guys,
You all ROCK.
McoreD
-
Jan 21st, 2004, 10:35 PM
#11
Pirates link shows how to read the values using the objects supplied with the .NET framework and unforuntately the framework doesn't provide a write method just reading ones.
-
Jan 21st, 2004, 10:48 PM
#12
Thread Starter
Addicted Member
Thank you very much for your complete Code Edneeis. 
I am using it now and it works Great!
Yours,
McoreD
-
Jan 22nd, 2004, 05:43 AM
#13
Thread Starter
Addicted Member
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Width
Hi Edneeis,
Everything else works fine 
I am doing something wrong here:
The following is in my app.Config
PHP Code:
<add key="WindowLeft" value="((System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2)" />
<add key="WindowTop" value="((System.Windows.Forms.Screen.PrimaryScreen.Bounds.width - Me.height) / 2)" />
When the Form loads, I expect the Form to do this:
VB Code:
Me.Left = AppSettingsManager.LoadAndGetValue("WindowLeft")
Me.Top = AppSettingsManager.LoadAndGetValue("WindowTop")
But I am not getting the expected result and I get the following error instead:
Additional information: Cast from string "((System.Windows.Forms.Screen.Pr" to type 'Integer' is not valid.
Hope you released what I was going to do.
Is it possible to pass this kind of information from the XML file to the Form at Form_Load?
Thank you,
McoreD
P.S: It works perfectly if I replace the XML code with (using numbers):
For example:
PHP Code:
<add key="WindowLeft" value="500" />
<add key="WindowTop" value="500" />
-
Jan 22nd, 2004, 10:56 AM
#14
It's as you said you must put a number in the xml. You can't put a variable or method name in xml and expect it to process it as code. Once its in the xml its just a string. Although if it is also going to be that formula "((System.Windows.Forms.Screen.PrimaryScreen.Bounds.width - Me.height) / 2)" then why does it even need to be dynamic or stored in the xml?
-
Jan 22nd, 2004, 01:41 PM
#15
Sleep mode
Originally posted by AtomSoft
for as google. That is my home page. I am a google freak. Google rocks but its tirering searching and searching and etc.. Ok if i ask for hel pwhy do you point me to another place to ask for help. Why not give me a straight link ?
I gave a direct link and you said it didn't help , though it's there to answer this question specifically . I think you're afraid to learn something new like Config files . But you can't say it didn't help .
do you use google ? if so why not search for me and send me the right link or give me the code yourself?
Yes, I use Google all the time and huh , you want direct link !!fine if I find one , but if I couldn't then it's your problem to find one and the help we can offer is just some tips like 'google it' .
I am not trying to get you mad but i get tired of replys that dont help. If you are going to reply it should be usefull. Thanks for your time.
We're talking about XML Files and you just jumped in saying this . Ofcourse this will not make any sense if you're talking about ini files and we're not .
~*McoreD*~ , I know your problem has been solved but to to extend your knowledge , why don't you have a look at dynamic properties ? It's another way to set controls's configuration without having to read/write settings .
-
Jan 22nd, 2004, 01:57 PM
#16
Originally posted by Pirate
~*McoreD*~ , I know your problem has been solved but to to extend your knowledge , why don't you have a look at dynamic properties ? It's another way to set controls's configuration without having to read/write settings .
Thats a good call! I second that. If the properties you are storing in a config file are parts of any control or things you can set at designtime then check at the top of the Property dialog at the Dynamic Properties section which just handles reading/writing from a config file for you.
-
Jan 22nd, 2004, 11:19 PM
#17
Thread Starter
Addicted Member
Originally posted by Edneeis
Once its in the xml its just a string. Although if it is also going to be that formula "((System.Windows.Forms.Screen.PrimaryScreen.Bounds.width - Me.height) / 2)" then why does it even need to be dynamic or stored in the xml?
Okay I will explain my need a bit more. 
In VB6, I used module (attached in my first post) to do the following:
VB Code:
Me.Left = sGetINI(App.Path & "\" & App.EXEName & "-Defaults.ini", "Window", "Form_Left", (Screen.Width - Me.Width) / 2)
Me.Top = sGetINI(App.Path & "\" & App.EXEName & "-Defaults.ini", "Window", "Form_Top", (Screen.Width - Me.Height) / 2)
As you can see, if there was no current setting for WindowLeft and WindowTop, then the form would start in the center of the screen. I didn't need to specify any value since the code was within the form.
I would like to do that in XML too. (without spefifying values). But now I seem it is impossible, since once it is in XML it is just a string. (I was just hoping that XML would pass that string to the Form while the Form loads. )
Thanks Pirate and Edneeis for the information about Dynamic Properties. I will have a look at them too. 
------------------------------------------------------------
I was using this workaround.
VB Code:
If Me.Left = -100 And Me.Left = -100 Then
Me.Left = (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Width) / 2
Me.Top = (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Height) / 2
End If
Cheers,
McoreD
-
Jul 24th, 2004, 04:23 PM
#18
Addicted Member
I am having issues here.
Here is my XLM File
Code:
<configuration>
<appSettings>
<add key="mydbconn" value="host=10.0.0.x, etc;"/>
</appSettings>
</configura
My program code is
Code:
dim aconfig as configuration.configurationsettings
dim mydbconn as string
mydbconn=aconfig.appsettings("mydbconn")
oconnection.connectionstring=mydbconn
Now it tells me that the value is null. So, I go to look for the config file and it is missing. So, I recreate it. Execute...and again it is gone from my BIN folder.
Any ideas?
-
Jul 24th, 2004, 05:38 PM
#19
Lively Member
That is because Bin is an Output folder, Visual Studio .NET copies your outputted files to there, so let's say your Application Configuration File's name is "app.config", it'll overrite it if exists previously the Bin dorectory.
To solve this problem, simpy edit the file from within Visual Studio .Net's IDE, that way it'll copy the correct data (I faced sucha situation but solved it right ahead).
Do you think my life is easy?
Do you think it's good to win?
do you think it's nice to kill?
Do you think learning is a must?
Do you think computers are nothing?
Do you think this post is stupid?
Do ypu think we're really humen?
DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !
-
Jul 24th, 2004, 05:49 PM
#20
Addicted Member
I ended up going into the Project Properties, Common Properties, Build and had to click on Supported Runtimes / CHANGE button and it created the config file for me...
I am sure there was another way - but even creating the app.config file from the project did not seem to work...
Thanks for the info... I found a lot of great things in the Properties in .NET.
Any info on project versions? (not Framework versions)
-
Jul 24th, 2004, 06:06 PM
#21
Lively Member
Originally posted by craigreilly
but even creating the app.config file from the project did not seem to work...
Did you create it and fill it up with your settigns or just added it to the project?
About the Project version, as I understtod you want that number appears when you clikc properties->Version Tab->Product Version? ! ?
This simply can be changed by going the Assembly Information File ("AssemblyInfo.vb"), there in the bottom of the file you will find an attribute like this:
Code:
<Assembly: AssemblyVersion("1.0.*")>
Change the first two numbers as your taste.
Do you think my life is easy?
Do you think it's good to win?
do you think it's nice to kill?
Do you think learning is a must?
Do you think computers are nothing?
Do you think this post is stupid?
Do ypu think we're really humen?
DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !
-
Jul 24th, 2004, 07:04 PM
#22
Addicted Member
I did get the config working... and am now able to load the info I need.
I work on my project from home sometimes and needed to be able to run the code and access the remote mySQL Database. This is much easier - just changing the config file to reflect the correct IP Address)
As far as the version goes - I played with that. When the config file version requirement is higher than the code version it tells me the .NET Framework is out of date. What I am looking for is to tell me the Program is out of date and needs to be updated. Sometimes I can not update a workstation because someone is on vacation and they are very particular about people going in their office.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|