by Jeffrey C. Tatum (5 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (6 Votes)
INI Read and INI Write made simple. I included examples in each function. If you like my codes, then please vote for me. But only if you like them. Thanks =)
API Declarations'INI Read and Write
Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName _
As String, lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpRetunedString As String, ByVal nSize As Long, _
ByVal lpFilename As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName _
As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lplFileName As String) As Long
Public Function INIRead(iAppName As String, iKeyName As String, iFileName As String) As String
'Example:
'x = INIRead("boot", "shell", "C:\WINDOWS\system.ini")
Dim iStr As String
iStr = String(255, Chr(0))
INIRead = Left(iStr, GetPrivateProfileString(iAppName, ByVal iKeyName, "", iStr, Len(iStr), iFileName))
End Function
Public Function INIWrite(iAppName As String, iKeyName As String, iKeyString As String, iFileName As String)
'Example:
'x = INIWrite("boot", "shell", "Explorer.exe", "C:\WINDOWS\system.ini")
r% = WritePrivateProfileString(iAppName, iKeyName, iKeyString, iFileName)
End Function