INI files

Hey,

I searched MSDN for this but I could not find anything on it...

How do you have the program recongnize a .ini file?

I have called it load.ini

and this is what it is inside of it:

[firstload]

firsttime = 1
I am trying to make it so that in the Private Sub Form_Load it will

look for the ini file and read it, is firsttime = 1 then it is going to

open up a dialog, otherwise it will do nothing, I can do all of that, I

just need to know how to have it find the ini file...

I placed the ini file in the project's folder...
Thanks :)

[563 byte] By [progames25] at [2007-12-23]
# 2
I am using Visual Basic 2005...
Thanks :)
progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Anyone?
progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

ok..I think I almost got it...but is this even C# 2005?

IniStructure Ini = IniStructure.ReadIni("file:///" + Application.StartupPath + "/Opacity.ini");

string[] allCategories = Ini.GetCategories();

string[] keysInGlobal = Ini.GetKeys("Opacity");

string testKeyValue = Ini.GetValue("Opacity", "1");

Becuase I get an error with this part of the code:

IniStructure and the other IniStructure...

Thanks :)

progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
EDIT: I get the same errors when I try to use the code as well.
EDIT2: I read an article earlier but can't seem to find it. Anyhoot it talked about creating, reading and writing ini files through:

[DllImport("kernal32")]
blah blah blah

Unfortunately.... I have no idea how to use the above code...

DaveS.Anderson at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
Private Class INI
Private Declare Ansi Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Ansi Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Private Path As String
Public Sub New(ByVal path As String)
Me.Path = path
End Sub
Public Function Read(ByVal section As String, ByVal key As String) As String
Dim value As String = Nothing
Dim v As Integer
Dim strTemp As String = ""
strTemp = strTemp.PadLeft(255, Chr(0))
v = GetPrivateProfileString(section, key, Nothing, strTemp, 255, Me.Path)
If v > 0 Then value = strTemp.Substring(0, v)
Return value
End Function
Public Sub Write(ByVal section As String, ByVal key As String, ByVal value As String)
WritePrivateProfileString(section, key, value, Me.Path)
End Sub
End Class
AndrewVos at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7

[firstload]
firsttime = 1

To read this file:

dim ini as new INI(filePath)

dim firstTime as integer = cint(ini.Read("firstload","firsttime"))

AndrewVos at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
I wish I knew Visual Basic, lol. I know C# and C++, if you can translate into either of those that would be great. If not I will use some logical reasoning to translate the VB. :)
DaveS.Anderson at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 9

Broaden your horizons :)

VB isn't so hard to understand, what part can't u understand?

AndrewVos at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 10
The keywords and phrases.

As for broadening my horizons...lol. I know html, c++ and C#. I am teaching myself asp .net as well.... not to mention i have a company-in-progress to run here. :) so not much time for anymore learning.

DaveS.Anderson at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 11

wha? ok so many posts with code...lol

umm..ok I will tyr to understand what you are all trying to tell my with C# and VB...

progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 12
you are better of storing such configuration in an xml file - xml is pretty much a replacement of ini configuration files, and is much better to navigate/find the node you want to read the value from than an ini file.
ahmedilyas at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 13

uu, ok...I guess I will do an XML file for the first startup and other options...

Thanks :)

progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 14

ummm ahmedilyas... ... ...I am making a new class for this XML file...but I am looking in the Bookmarks.cs class file...and se this:

[XmlRoot("Bookmark")]

what does that do? And should I change "Bookmark" to "SBookmarks" since SBookmarks is the name of the bookmark XML file...

Thanks :)

progames25 at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms General...