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

Comments

  1. thanks, needed that.

    ReplyDelete
  2. Nice function. Showing both the use of the kernal32.dll, and the functionality of reading an .ini file.

    Good Work.

    ReplyDelete
  3. Any Idea how to read whole section data?

    ReplyDelete

Post a Comment

Popular posts from this blog

Test Batch Runner - Run QTP Scripts from xls file

Selenium: db and excel data into maps

Python: get entire workbook data cell by cell