Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


964


IniPath = CurrentProject.Path & “\”
Filename = IniPath & “TEST.INI”
Section = “Settings”
KeyName = “AppTitle”
Default = “Not Found”
ReturnBuffer = String$(128, 0)
BufferSize = Len(ReturnBuffer)
RetVal = apiGetPrivateProfileString(Section, _
KeyName, Default, ReturnBuffer, _
BufferSize, Filename)
GetPrivateProfileString = ReturnBuffer
End Function

GetPrivateProfileIntA
The GetPrivateProfileIntA function returns an integer value from an application-specific
.ini file.

Declare Function apiGetPrivateProfileInt _
Lib “Kernel32” _
Alias “GetPrivateProfileIntA”( _
ByVal lpSection As String, _
ByVal lpszKey As String, _
ByVal dwDefault As Long, _
ByVal lpszFilename As String) As Long

GetPrivateProfileIntA accepts a Section, KeyName, default, and filename like
GetPrivateProfileStringA but does not accept a string buffer. If the function is successful,
it returns the integer value. The GetTitleSetting wrapper shows how to use GetPrivate
ProfileIntA:

Function GetTitleSetting() As Long
Dim Section As String
Dim KeyName As String
Dim Default As Long
Dim Filename As String
Dim RetVal As Long
Dim IniPath As String
IniPath = CurrentProject.Path & “\”
Filename = IniPath & “TEST.INI”
Section = “Settings”
KeyName = “TitleBar”
Default = 1
RetVal = apiGetPrivateProfileInt( _
Section, KeyName, Default, Filename)
GetTitleSetting = RetVal
End Function
Free download pdf