Purpose |
Reads a string from the specified section of a Windows profile (*.ini file)
|
Author | Date of code (original) | Updated on | Date of page (original) | Updated on |
Bill Thoen bthoen@ctmap.com |
09Jan2001
|
09Jan2001
|
09Jan2001
|
09Jan2001
|
Restrictions on use |
This module is distributed under the terms of the Lesser GNU General
Public License. Restrictions on the use of this work in a commercial
application or derivative work is described in the Lesser GNU General
Public License page at:
http://www.fsf.org/copyleft/lesser.html
|
Description |
ProfileRead returns a string value from a private profile (.INI)
file. If the value is not found, it returns the value contained in
the Default passed parameter.
|
External resources |
Windows KERNEL32 DLL
|
Declare statement of sub_function. Include in your program. Copy/Paste if needed. |
function ProfileRead ( ByVal sSection as String, 'Section name (in [] brackets) ByVal sKey as String, 'Key variable in section ByVal sDefault as string, 'Default value ByVal sFile as String 'Profile filename ) as string |
Returned value(s) (function only) |
Value read or default, returned as string
|
Other required declare statement(s). Include in your program. Copy/Paste if needed. |
none |
MapBasic Code. Copy/Paste if needed.
|
include "Profile.def" Declare Function GetPrivateProfileString32 Lib KERNEL32 alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, lpReturnedString As String, ByVal nSize As Smallint, ByVal lpFileName As String) As Smallint function ProfileRead ( ByVal sSection as String, ByVal sKey as String, ByVal sDefault as string, ByVal sFile as String) as string Dim sRetVal As String dim nStatus as integer sRetVal = String$(255, "X") nStatus = GetPrivateProfileString32 ( sSection, sKey, sDefault, sRetVal, Len(sRetVal), sFile) ProfileRead = sRetVal end function |
Availability for download |
Profile.zip |
Example |
include "Profile.def" '... dim sProfile as string sProfile = ApplicationDirectory$()+"Example.ini" sColor = ProfileRead ("Main", "DefaultColor", "", sProfile) 'If there was a key called "DefaultColor" in the [Main] section of Example.ini, then sColor is set to this key. Otherwise, sColor is blank. |
Comments |
|
See also |
ProfileWrite( ) |