Read and Write to an *.INI file
Read and Write to an *.INI file
API Declarations
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Rate Read and Write to an *.INI file
(2(2 Vote))
'************************************************************************
'DESCRIPTION: WRITES INFORMATION TO AN INI FILE
'INPUTS: SZSECTION, SZFIELD, SZVALUE
'OUTPUTS: WRITEINIFILE
'AUTHOR: EB
'DATE EDITED: 2/22/01
'************************************************************************
On Error GoTo Err_WriteINIFile
Dim strProcName As String
strProcName = "WriteINIFile"
Dim Success As Long
Success = WritePrivateProfileString(szSection, szField, szValue, App.Path + "\IniName.INI")
If Success = False Then
WriteINIFile = False
Else
WriteINIFile = True
End If
Exit_WriteINIFile:
Exit Function
Err_WriteINIFile:
MsgBox Err.Number & Err.Description & vbCrLf & strProcName, vbCritical
GoTo Exit_WriteINIFile
End Function
Public Function GetINIFile(ByVal szSection As String, ByVal szField As String)
'**********************************************************************
'DESCRIPTION: GETS INFORMATION FROM AN INI FILE
'INPUTS: SZSECTION, SZFIELD
'OUTPUTS: GETINIFILE
'AUTHOR: EB
'DATE EDITED: 2/22/01
'**********************************************************************
On Error GoTo Err_GetINIFile
Dim strProcName As String
Dim nRet As Integer
Dim szFileName As String
Dim szBuffer As String
Dim szDefault As String
Dim nTempLength As Integer
strProcName = "GetINIFile"
szDefault = ""
szBuffer = String(80, " ")
nRet = GetPrivateProfileString(szSection, szField, szDefault, szBuffer, Len(szBuffer), App.Path + "\IniName.INI")
If nRet > 0 Then
GetINIFile = Left(szBuffer, nRet)
Else
GetINIFile = szDefault
End If
Exit_GetINIFile:
Exit Function
Err_GetINIFile:
MsgBox Err.Number & Err.Description & vbCrLf & strProcName, vbCritical
GoTo Exit_GetINIFile
End Function
Read and Write to an *.INI file Comments
No comments yet — be the first to post one!
Post a Comment