GetPrivateProfileInt Function

Declare Function GetPrivateProfileInt Lib "kernel32.dll" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long

Platforms: Win 32s, Win 95/98, Win NT

GetPrivateProfileInt reads an integer value from any INI file. The parameters passed to the function specify which value will be read from. If successful, the function returns the value read. If the value you specify does not exist or is a string (i.e., not a number), the value specified as nDefault is returned. Note that INI file support is only provided in Windows for backwards compatibility; using the registry to store information is preferred.

lpApplicationName
The header of the INI file section the value is in.
lpKeyName
The name of the value to read.
nDefault
The value to return if a valid value cannot be read. Make it something that would definitely not be read, such as -1.
lpFileName
The filename of the INI file to read from.

Example:

' Read the "version" value under the "[programinfo]" section
' of the INI file C:\MyProgram\config.ini
Dim version As Long  ' receives the value returned from the INI file

' Read the value from the INI file, returning -1 if it can't find the value
version = GetPrivateProfileInt("programinfo", "version", -1, "C:\MyProgram\config.ini")
' Display the result
If version = -1 Then  ' failure
  Debug.Print "Could not read the information from the INI file."
Else
  Debug.Print "Version number:"; version
End If

See Also: GetPrivateProfileString, GetProfileInt
Category: INI Files

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getprivateprofileint.html