|
-
Jun 5th, 2005, 04:39 PM
#1
Thread Starter
Hyperactive Member
read/write to ini file help...[SOLVED]
i am trying to read from an ini file (config.ini) I have searched for this and most of it is in vb6/classic... im in .net....
this is my config.ini contents
Code:
[Main]
Username=bumbum
Password=Conaticus
and wut i wanted to do is read from that and display the username and password in the corresponding textboxes. Problem is i dont know how to even save teh info to an ini let alone read from it.... i checked my "Microsoft Visual Studio .NET 2003 Documentation" that came with it...i checked thru my book...
but i dont know wut to do... so as a last resort im here asking you ppl for help.... I thank you in advance for all the help you give me.
Last edited by PlaGuE; Jun 7th, 2005 at 04:53 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 5th, 2005, 08:28 PM
#2
Re: read/write to ini file help...
INI files are not part of the .NET world. If you have the choice of file format, I strongly suggest you use serialization and XML instead. As an example, you can create a UserCredentials class that has a UserName property and a Password property. To save an object of this type to a file you simply serialize it to an XML file, which takes four lines of code. Another four lines of code deserializes the file to an object.
VB Code:
Private Sub SaveUserCredentials(ByVal user As UserCredentials)
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that creates the file.
Dim stream As New IO.FileStream(Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml", IO.FileMode.Create)
'Convert the object to XML.
serializer.Serialize(stream, user)
'Close the file.
stream.Close()
End Sub
Private Function LoadUserCredentials() As UserCredentials
Dim userPath As String = Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml"
If System.IO.File.Exists(userPath) Then
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that opens the file.
Dim stream As New IO.FileStream(userPath, IO.FileMode.Open)
'Convert the XML to an object.
'Each function has a local variable of the same name and type that can be assigned to rather than using Return.
LoadUserCredentials = serializer.Deserialize(stream)
'Close the file.
stream.Close()
Else
'You can create a new object with default values if no file exists.
Return New UserCredentials
End If
End Function
If you are determined to use an INI file, you will save the file using a StreamWriter and its WriteLine method. You will then open the file with a StreamReader and its ReadLine method. It is then up to you to parse each line as it is read. See the help topics "Writing Text to a File" and "Reading Text from a File".
-
Jun 5th, 2005, 09:38 PM
#3
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
I think i will try both methods and then see which one works best...
I had my heart set on INI cuz idk i see it alot and im not familiar with XML...
Ill post back with my results
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 5th, 2005, 10:01 PM
#4
Re: read/write to ini file help...
 Originally Posted by PlaGuE
I think i will try both methods and then see which one works best...
I had my heart set on INI cuz idk i see it alot and im not familiar with XML...
Ill post back with my results
Now is the time to familiarise yourself with XML as it is poised to take over the world at any moment 
Seriously though, what you are doing currently is a simple problem and will therefore be an easy introduction to XML and serialization. If you want to save 100, 1000 or 1000000 values, serialization still only requires four lines of code, whereas saving and parsing INI files would quickly get time consuming and complex. Microsoft are obviously strongly behind XML and INI files have no place in their vision of the future, or the present for that matter. XML also has many other applications so this is a good way to open yourself up to those possibilities.
-
Jun 6th, 2005, 01:05 AM
#5
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
i stuck the code in the form that has the textboxes that show the information....
the only error i get is the Usercredentials part which isnt defined.
i still am kinda new to all this...becuz of school and all i dont get much time to do this.... but with summer coming and school almost over i hope to get more into it.
[EDIT]
I fixed the usercredentials.... forgot to make it into a class... lol...
but now to ask how do i have it so it shows the username in username textbox and password in password textbox..
then i will try and do this on my own but im sure to have bad luck so ill post now and keep trying...
how to save it...lol easy it should be... but to me its still french... but with all your help i am learning to speak french...lol
Last edited by PlaGuE; Jun 6th, 2005 at 01:16 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 01:15 AM
#6
Re: read/write to ini file help...
The UserCredentials class is one that you need to create yourself. Its defintion would look something like this:
VB Code:
Public Class UserCredentials
Private m_UserName As String
Private m_Password As String
Public Property UserName() As String
Get
Return Me.m_UserName
End Get
Set(ByVal Value As String)
Me.m_UserName = Value
End Set
End Property
Public Property Password() As String
Get
Return Me.m_Password
End Get
Set(ByVal Value As String)
Me.m_Password = Value
End Set
End Property
End Class
You can create classes similar to this whenever you want to persist data between sessions. I usually have a ProgramOptions class for every project I work on. Then the options for the app are saved between sessions and are tied to an app instance, unlike if the options were stored in a shared database.
-
Jun 6th, 2005, 01:17 AM
#7
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
wow taht was quick... even while i was editing my post
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 01:29 AM
#8
Re: read/write to ini file help...
Once you have a UserCredentials object it is up to you to use the UserName and Password properties to populate your TextBoxes, and then to write back any changes. If you want to get more advanced, you could make your class suitable for databinding, which I think means implementing the IList interface.
-
Jun 6th, 2005, 01:38 AM
#9
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Reference to last post....(im goin to bed so i wont see it till tommorow)
"... .... how do i have it so it shows the username in username textbox and password in password textbox..."
"...i will try and do this on my own but im sure to have bad luck so ill post now and keep trying..."
"how to save it...lol easy it should be... but to me its still french..."
once my apps done im sure to include vbforums.com in my about/readme for all the help you've given me
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 01:47 AM
#10
Re: read/write to ini file help...
 Originally Posted by jmcilhinney
INI files are not part of the .NET world. If you have the choice of file format, I strongly suggest you use serialization and XML instead. As an example, you can create a UserCredentials class that has a UserName property and a Password property. To save an object of this type to a file you simply serialize it to an XML file, which takes four lines of code. Another four lines of code deserializes the file to an object.
VB Code:
Private Sub SaveUserCredentials(ByVal user As UserCredentials)
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that creates the file.
Dim stream As New IO.FileStream(Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml", IO.FileMode.Create)
'Convert the object to XML.
serializer.Serialize(stream, user)
'Close the file.
stream.Close()
End Sub
Private Function LoadUserCredentials() As UserCredentials
Dim userPath As String = Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml"
If System.IO.File.Exists(userPath) Then
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that opens the file.
Dim stream As New IO.FileStream(userPath, IO.FileMode.Open)
'Convert the XML to an object.
'Each function has a local variable of the same name and type that can be assigned to rather than using Return.
LoadUserCredentials = serializer.Deserialize(stream)
'Close the file.
stream.Close()
Else
'You can create a new object with default values if no file exists.
Return New UserCredentials
End If
End Function
If you are determined to use an INI file, you will save the file using a StreamWriter and its WriteLine method. You will then open the file with a StreamReader and its ReadLine method. It is then up to you to parse each line as it is read. See the help topics "Writing Text to a File" and "Reading Text from a File".
VB Code:
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
Me.userNameText.Text = currentUser.UserName
Me.passwordText.Text = currentUser.Password
'Do whatever.
'Get the updated user credentials.
currentUser.UserName = Me.userNameText.Text
currentUser.Password = Me.passwordText.Text
'Save the updated user credentials.
Me.SaveUserCredentials(currentUser)
-
Jun 6th, 2005, 02:19 AM
#11
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
i hada let dog outside for a min so i thought i'd come and check...
You may call me noob right now... god knows i am...
i know i should figure tis out on my own...and i will but just incase i cant find where... can you give me an example...
i would think that...
VB Code:
Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
'Save the updated user credentials.
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
currentUser.UserName = Me.UserName.Text
currentUser.Password = Me.password.Text
Me.SaveUserCredentials(currentUser)
End Sub
VB Code:
Private Sub mnuBotConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
Me.UserName.Text = currentUser.UserName
Me.password.Text = currentUser.Password
'Do whatever.
End Sub
i get no underlined code there...
but when i run it and i access the form it exeptions me
Last edited by PlaGuE; Jun 6th, 2005 at 02:26 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 04:09 AM
#12
Re: read/write to ini file help...
Firstly, in your Apply_Click procedure you don't need to load the credentials. It won't do any harm but you might as well just create a new object as you are setting the properties anyway.
Secondly, if you are asking for help on an unhandled exception you need to give details of what the exception was and where it occurred. The first action you should take in this situation is to click the Break button on the unhandled exception dialogue and examine all your variables to make sure they are what you expect them to be. You can mouse over some variables to get their value or use the Autos, Locals and Watch windows.
-
Jun 6th, 2005, 01:53 PM
#13
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Code:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll
Additional information: There is an error in XML document (0, 0).
then when it brings me to the System.Xml.Serialization.XmlSerializer.Deserialize it goes straight to
Code:
0000020b mov dword ptr [ebp-8],0
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 02:09 PM
#14
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
im thinking its not reading the xml...
this is my first BIG project...
usually its just lil things... but none with usernames and pw's and stuff...
Last edited by PlaGuE; Jun 6th, 2005 at 02:30 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 05:19 PM
#15
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
the error is situated in
VB Code:
Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
'Save the updated user credentials.
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
currentUser.UserName = Me.UserName.Text
currentUser.Password = Me.password.Text
Me.SaveUserCredentials(currentUser)
End Sub
'AND
Private Sub mnuBotConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the user credentials.
'Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
'Me.UserName.Text = currentUser.UserName
'Me.password.Text = currentUser.Password
'Do whatever.
End Sub
i stuck the ' there to test to see if it was the problem
Last edited by PlaGuE; Jun 6th, 2005 at 08:20 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 08:12 PM
#16
Re: read/write to ini file help...
It seems as though your XML file is probably not valid XML. Unless you know exactly what the format of the XML file should be, the best way to create it in the first place is by serializing an object. Are you checking that the file exists before trying to deserialize? If you create an empty file and try to deserialize it you would most surely get an error.
-
Jun 6th, 2005, 08:46 PM
#17
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Yes. it created itself.. and it is empty...
would sumtin like
Code:
"UserCredentials.XML"
<MyClass>
<MyObjectProperty>
<UserName>My String</UserName>
</MyObjectProperty>
</MyClass>
be it
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 09:06 PM
#18
Re: read/write to ini file help...
That's why, in my original code for LoadUserCredentials, I included the "If File.Exists" part. A valid XML file for your class will look something like this:
Code:
<?xml version="1.0"?>
<UserCredentials xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserName>user</UserName>
<Password>password</Password>
</UserCredentials>
I never write these XML files by hand. Whenever I use this method I let the first run of my code create the file for me by serializing an object. If you want to distribute an empty file with your app you can simply edit out the actual UserName and Password values. These values can then be entered manually for each installation or via your app.
-
Jun 6th, 2005, 09:24 PM
#19
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
so the IF file exists part is this:
VB Code:
'Load UserCredentials
Private Function LoadUserCredentials() As UserCredentials
Dim userPath As String = Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml"
If System.IO.File.Exists(userPath) Then
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
from
VB Code:
'Load UserCredentials
Private Function LoadUserCredentials() As UserCredentials
Dim userPath As String = Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml"
If System.IO.File.Exists(userPath) Then
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that opens the file.
Dim stream As New IO.FileStream(userPath, IO.FileMode.Open)
'Convert the XML to an object.
'Each function has a local variable of the same name and type that can be assigned to rather than using Return.
LoadUserCredentials = serializer.Deserialize(stream)
'Close the file.
stream.Close()
Else
'You can create a new object with default values if no file exists.
Return New UserCredentials
End If
End Function
am i right?
and the code added to the XML file manually is
Code:
<?xml version="1.0"?>
<UserCredentials xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserName>hey</UserName>
<Password>dude</Password>
</UserCredentials>
im sorry if im annoying you ppl... im only asking questions cuz im not sure..
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 09:34 PM
#20
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
this is the form its situated in...
VB Code:
' recently added to see if it would help
Imports System Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO
Imports Microsoft.VisualBasic
'it didnt
Public Class mnuBotConfig
Inherits System.Windows.Forms.Form
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Starcraft_Product.CheckedChanged
End Sub
Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WarCraftIIITFT_Product.CheckedChanged
End Sub
Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter
End Sub
Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
'Save the updated user credentials.
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
currentUser.UserName = Me.UserName.Text
currentUser.Password = Me.password.Text
Me.SaveUserCredentials(currentUser)
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub mnuBotConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
Me.UserName.Text = currentUser.UserName
Me.password.Text = currentUser.Password
'Do whatever.
End Sub
Private Sub Options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Options.Click
Dim Options As New options
Options.Show()
Me.Close()
End Sub
Private Sub password_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles password.TextChanged
End Sub
'Save UserCedentials
Private Sub SaveUserCredentials(ByVal userame As UserCredentials)
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that creates the file.
Dim stream As New IO.FileStream(Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml", IO.FileMode.Create)
'Convert the object to XML.
serializer.Serialize(stream, UserName)
'Close the file.
stream.Close()
End Sub
'Load UserCredentials
Private Function LoadUserCredentials() As UserCredentials
Dim userPath As String = Application.StartupPath & IO.Path.DirectorySeparatorChar & "UserCredentials.xml"
If System.IO.File.Exists(userPath) Then
'The object that performs the serialization.
Dim serializer As New Xml.Serialization.XmlSerializer(GetType(UserCredentials))
'The object that opens the file.
Dim stream As New IO.FileStream(userPath, IO.FileMode.Open)
'Convert the XML to an object.
'Each function has a local variable of the same name and type that can be assigned to rather than using Return.
LoadUserCredentials = serializer.Deserialize(stream)
'Close the file.
stream.Close()
Else
'You can create a new object with default values if no file exists.
Return New UserCredentials
End If
End Function
Private Sub UserName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UserName.TextChanged
End Sub
End Class
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 6th, 2005, 09:50 PM
#21
Re: read/write to ini file help...
In the LoadUserCredentials method, the code checks for the existence of the desired file. If the file exists it is deserialized into an object. If the file does not contain valid XML for the specified type an exception will be thrown. If the file does not exist, a new object is created. The reason I code it like this is so that when you run your app for the first time and no XML file exists, an empty object is created. You can then populate the properties of this empty object and serialize it to create the XML file. Then when your app is run the next time, the file will exist and it will be deserialized. If you want the file to be there the first time you run your app then you must write the XML file by hand. You must make sure that it is valid XML, though, as even a single character in the wrong place means the whole lot is no good. If you paste the code from my previous post into a file and edit the value of the UserName and Password you should find that it will work. I don't know if it's been mentioned before but my code also assumes that the XML file is in your app's program folder. In short, the answer to the question in your second last post is "Yes".
-
Jun 6th, 2005, 10:45 PM
#22
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 01:26 AM
#23
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Okay... IM SO DUMB....lol...really i am...
ive been at this problem for hours....
wut ive come to relize is... idk where to stick the code...
idk where to stick it so that when i click apply it saves the code... or when i load the form it loads the data strings into the correct boxes...
this was the right thing...to do..?:
VB Code:
Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
'Save the updated user credentials.
'Load the user credentials.
Dim currentUser As UserCredentials = Me.SaveUserCredentials(currentUser)
currentUser.UserName = Me.UserName.Text
currentUser.Password = Me.password.Text
End Sub
'AND
Private Sub mnuBotConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
Me.UserName.Text = currentUser.UserName
Me.password.Text = currentUser.Password
'load info into correct boxes
End Sub
and with
Code:
<?xml version="1.0"?>
<UserCredentials xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserName>boo</UserName>
<Password>dude</Password>
</UserCredentials>
is that right... or should it be like
Code:
<?xml version="1.0"?>
<UserCredentials xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserName>m_UserName</UserName>
<Password>m_Password</Password>
</UserCredentials>
if you need anymore information in which to help me with this... just ask... im at a complete loss...
Last edited by PlaGuE; Jun 7th, 2005 at 01:41 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 01:34 AM
#24
Re: read/write to ini file help...
The last lot of code you posted looks like it should work OK. It seems to me that the issue was that your XML was invalid. Simply paste the XML code I provided into a blank text file, edit the UserName and Password values if you want and then save it as UserCredentials.xml in your program folder.
-
Jun 7th, 2005, 02:44 AM
#25
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
okay well... i got past the part where it gives error at opening of the form...
VB Code:
Private Sub mnuBotConfig_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
'Populate the text boxes with the user credentials.
Me.UserName.Text = currentUser.UserName
Me.password.Text = currentUser.Password
'load info into correct boxes
but it dont load the credentials...maybe i dont have any yet...but I can fix this later...
when i hit break it goes here
VB Code:
Public Class UserCredentials
Private m_UserName As String
Private m_CDkey As String
Private m_Password As String
Public Property UserName() As String
Get
Return Me.m_UserName
End Get
Set(ByVal Value As String) 'highlighted ByVal Value As String
Me.UserName = Value
End Set
End Property
Public Property Password() As String
Get
Return Me.m_Password
End Get
Set(ByVal Value As String)
Me.m_Password = Value
End Set
End Property
End Class
its caused by this
VB Code:
Private Sub Apply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Apply.Click
'Save the updated user credentials.
'Load the user credentials.
Dim currentUser As UserCredentials = Me.LoadUserCredentials()
currentUser.UserName = Me.UserName.Text
currentUser.Password = Me.password.Text
Me.SaveUserCredentials(currentUser)
End Sub
good thing is, is at least it loads the form...
Last edited by PlaGuE; Jun 7th, 2005 at 03:23 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 03:08 AM
#26
Re: read/write to ini file help...
If the code you have posted is correct, you are referring to the UserName property when you are setting the UserName property. This would create an infinite recursion and lead to an OutOfMemoryException if I'm not mistaken. You should be referring to the m_UserName variable, i.e.should beIf this is just a typo on your part, please let me know the details of the exception.
-
Jun 7th, 2005, 03:27 AM
#27
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Last edited by PlaGuE; Jun 7th, 2005 at 03:31 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 03:33 AM
#28
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
THANKS... now it works...
If i wasnt straight id say " I LUV YOU"
if i had a million dollars is give it to you...
you... you... I LUV YOU MAN... this was giving me a headache ... and you gave me the asprin..lol...
Sorry... im jsut very happy
Last edited by PlaGuE; Jun 7th, 2005 at 03:50 AM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 03:50 AM
#29
Re: read/write to ini file help...
Your extremely heterosexual thanks is quite enough.
Now, about the fact that your password is saved as plain text...
-
Jun 7th, 2005, 04:49 AM
#30
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
well accually for wut its being used for ... its okay that its not encrypted...
how would i encrypt it tho...if needbe?
Last edited by PlaGuE; Jun 7th, 2005 at 04:51 PM.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Jun 7th, 2005, 07:12 AM
#31
Re: read/write to ini file help...
I haven't used encryption a lot so there is a great deal I don't know about it. Whenever I have employed encryption, though, I have used the Data Protection API. Go to the MSDN library on-line and search for DPAPI for more info.
-
Jun 7th, 2005, 01:04 PM
#32
Thread Starter
Hyperactive Member
Re: read/write to ini file help...
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
-
Aug 25th, 2005, 04:46 AM
#33
Fanatic Member
Re: read/write to ini file help...[SOLVED]
How can I read such a xml file till the end?
not able to figureout!
-
Aug 25th, 2005, 05:04 AM
#34
Re: read/write to ini file help...[SOLVED]
 Originally Posted by sridharavijay
How can I read such a xml file till the end?
not able to figureout!
When you call Deserialize it reads the entire file and constructs an instance of the class from the contents. One interesting point to note is that no constructor is called.
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
|