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 :)
I am using Visual Basic 2005...
Thanks :)
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 :)
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...
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
[firstload]
firsttime = 1
To read this file:
dim ini as new INI(filePath)
dim firstTime as integer = cint(ini.Read("firstload","firsttime"))
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. :)
Broaden your horizons :)
VB isn't so hard to understand, what part can't u understand?
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.
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...
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.
uu, ok...I guess I will do an XML file for the first startup and other options...
Thanks :)
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 :)