How to read data from ini file without using fso
By using kernel32.dll method GetPrivateProfileString
Example: Say we have following INI file:
INI file:
[Environment]
Ashish=7.5
Jindal=2323
Sumit=2233
[gari]
ashi=32
sumi="ashsih jindasaksas vfd ashisdjvfusbasjbas
Code to read the file:
Dim a
sIniFile="C:\Documents and Settings\ashish.jindal\Desktop\EV.ini"
print zGen_GetIni(sIniFile, "Environment", "Ashish", sDefault)
print zGen_GetIni(sIniFile, "gari", "sumi", sDefault)
Function zGen_GetIni(sIniFile, sSection, sKey, sDefault)
Dim iRet, sReturnString
Extern.Declare micLong, "GetPrivateProfileString", "kernel32.dll", "GetPrivateProfileStringA", micString, micString, micString, micString + micByRef, micDWord, micString
iRet = Extern.GetPrivateProfileString( sSection, sKey, sDefault, sReturnString, 256, sIniFile )
If iRet > 0 Then
zGen_GetIni = sReturnString
Else
zGen_GetIni = sDefault
End If
End Function
thanks, needed that.
ReplyDeleteNice function. Showing both the use of the kernal32.dll, and the functionality of reading an .ini file.
ReplyDeleteGood Work.
Any Idea how to read whole section data?
ReplyDelete