In the ReadIniData routine You will see these lines:
strDatabasePath = objRec("Path").Value
strDatabaseNavn = objRec("DatabaseName").Value
the variables strDatabasePath and strDatabaseNavn are global string variables.
All You need is to place this code in the form load event: ReadIniData
You now have all You need, I suppose, to call or open any file etc.
The database are very simple: a Table called DataPath, and two string fields called Path and DatabaseName.
There are another way to get a INI simular file, which is a XML file. I'm not any specialist within XML but I made this in the week-end. It might be uesfull.
First:
You will have to create a XML document:
Open a Notepad document and paste this into the document:
'***********************************************************
<?xml version="1.0" encoding="UTF-16" ?>
- <Collection>
-
- <Settings Id="1">
<Title>D:\VS Projekter\Pladeberegning\PladeBeregning\bin\Debug</Title>
</Settings>
-
- <Settings Id="2">
<Title>Pladeberegning.mdb</Title>
</Settings>
</Collection>
'**************************************************
Save the Notepad document as "AppData.xml" and place it in the output directory of Your program:
"c:\'VB Project'\'Projectname'\bin\debug" - or whatever path it is
Next:
Create a new Module named modXML and paste this code into the module:
Imports
System.Xml
Imports
System.Text
'Module
modXml ********** the code above must be placed in top of the module
Public strDatabaseNavn As String
Public strDatabasePath As String
Public Function ReadNode(ByVal Id As Integer) As String
TryDim doc As XmlDocument = New XmlDocument()
doc.Load(
My.Application.Info.DirectoryPath & "\AppData.xml")Dim nodeList As XmlNodeList = doc.SelectNodes("//Settings")Dim node As XmlNode
node = nodeList.Item(Id)
Return node.FirstChild.InnerText
Catch xmlex As XmlException ' Handle the Xml Exceptions here.
MsgBox(xmlex.Message)
Return ""End Try
End FunctionPublic Sub WriteNode(ByVal Id As Integer, ByVal strVal As String)
TryDim doc As XmlDocument = New XmlDocument()
doc.Load(
My.Application.Info.DirectoryPath & "\AppData.xml")Dim nodeList As XmlNodeList = doc.SelectNodes("//Settings")Dim node As XmlNode
node = nodeList.Item(Id)
node.FirstChild.InnerText = strVal
doc.PreserveWhitespace =
TrueDim wrtr As XmlTextWriter = New XmlTextWriter(My.Application.Info.DirectoryPath & "\AppData.xml", Encoding.Unicode)
doc.WriteTo(wrtr)
wrtr.Close()
Catch xmlex As XmlException ' Handle the Xml Exceptions here.
MsgBox(xmlex.Message)
End Try
End Sub
'*********************
Finally:
In the form load event of Your program add this code:
'**********************************
strDatabasePath = ReadNode(0)
strDatabaseNavn = ReadNode(1)
'****************************************
The variables will now contain the information stored in the XML file.
You can update the XML file through tis code:
'***********************************************
WriteNode(0, strDatabasePath)
WriteNode(1, strDatabaseNavn)
'************************************
Hope You can use thise samples!!!!