Hi..
when i am doing a project i need an requirement to read and write the INI files.then i googled ,But i got only partly result..
lastly i found this solution to read INI files ,then i decide to write articles to read INI files...
First you have to declare a function to read and write INI files..
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.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Details About Declaration:
Function GetPrivateProfileString:
lpkeyname -->Denotes session of INI file
lpDefault---->Its return default value
lpReturnedString--->its gets the value from the INI file
nSize---->Declare a size for return string
lpFileName-->Its path of INI file
Function WritePrivateProfileString
lpApplicationName--->Session Name
lpKeyName---->
lpString------>Input text
lpFilename---->Its path of INI file
In form add two buttons one for Read INI files and another one to write.......
In an Button click event enter this code:
Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Read.Click
textbo1.text=Getinistring("Boys1","students")
End Sub
Public Function Getinistring(ByVal strKey As String, _
Optional ByVal strSection As String ) As String
Dim strValue As String
Dim intPos As Integer
strValue = Space(1024)
GetPrivateProfileString(strSection, strKey, "Not-Found", strValue, 1024, "D:\class.ini")
strValue = Mid(strValue, 1, Len(strValue) - 1)
strValue = Trim(Left(strValue, Len(Trim(strValue)) - 1))
Getinistring = strValue
End Function
Private Sub Write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Write.Click
Dim rec as long
rec=WritePrivateProfileString("students", "Boys1", Trim(textbo2.Text), "D:\class.ini")
End Sub
Sample INI File
i hope this really helpful to you plz post your valuable comments...............