J
J Romine
I used to have a DB that read and wrote to an .ini file. The DB is now
located on a new PC after a year of inacvtivity and the read and write do
not work.
The following code is what I had all in the same module.
Declare Function GetModuleUsage% Lib "kernel32" (ByVal hModule%)
Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
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
****************************************************************************
****************************
Function GetIniStr(app$, var$, file$, def$) As String
' app$ is the INI file major heading, e.g., [Database], [Graphics], etc.
' var$ is the INI file variable name under the major heading, e.g.,
DatabaseName, ODBCstring, etc.
' file$ is the full path and filename for the INI file.
' def$ is a default return string if the function is unable to find the
heading or variable. Could be 'ERROR' to let you know it failed.
Dim msg As String
Dim Response As Integer
On Error GoTo Errorcond
Dim temp As String
Dim x As Integer
temp$ = String$(145, 0) ' Size Buffer
x = GetPrivateProfileString(app, var, def, temp$, 145, file)
GetIniStr = Left$(temp$, x) ' Trim Buffer
Exit Function
Errorcond:
msg = "A problem has occurred while getting data from your .ini file.
Please contact your system administrator"
Response = MsgBox(msg, vbOKOnly + vbInformation, "Initialization Error")
End Function
****************************************************************************
****************************
Function SetIniStr(app$, var$, value$, file$) As Long
On Error GoTo Errorcond
' app$ is the INI file major heading, e.g., [Database], [Graphics], etc.
' var$ is the INI file variable name under the major heading, e.g.,
DatabaseName, ODBCstring, etc.
' file$ is the full path and filename for the INI file.
Dim msg As String
Dim Response As Integer
SetIniStr = WritePrivateProfileString(app, var, value, file)
Exit Function
Errorcond:
msg = "A problem has occurred while updating data in your .ini file.
Please contact your system administrator"
Response = MsgBox(msg, vbOKOnly + vbInformation, "Initialization Error")
End Function
located on a new PC after a year of inacvtivity and the read and write do
not work.
The following code is what I had all in the same module.
Declare Function GetModuleUsage% Lib "kernel32" (ByVal hModule%)
Declare Function GetPrivateProfileString Lib "kernel32" Alias
"GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
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
****************************************************************************
****************************
Function GetIniStr(app$, var$, file$, def$) As String
' app$ is the INI file major heading, e.g., [Database], [Graphics], etc.
' var$ is the INI file variable name under the major heading, e.g.,
DatabaseName, ODBCstring, etc.
' file$ is the full path and filename for the INI file.
' def$ is a default return string if the function is unable to find the
heading or variable. Could be 'ERROR' to let you know it failed.
Dim msg As String
Dim Response As Integer
On Error GoTo Errorcond
Dim temp As String
Dim x As Integer
temp$ = String$(145, 0) ' Size Buffer
x = GetPrivateProfileString(app, var, def, temp$, 145, file)
GetIniStr = Left$(temp$, x) ' Trim Buffer
Exit Function
Errorcond:
msg = "A problem has occurred while getting data from your .ini file.
Please contact your system administrator"
Response = MsgBox(msg, vbOKOnly + vbInformation, "Initialization Error")
End Function
****************************************************************************
****************************
Function SetIniStr(app$, var$, value$, file$) As Long
On Error GoTo Errorcond
' app$ is the INI file major heading, e.g., [Database], [Graphics], etc.
' var$ is the INI file variable name under the major heading, e.g.,
DatabaseName, ODBCstring, etc.
' file$ is the full path and filename for the INI file.
Dim msg As String
Dim Response As Integer
SetIniStr = WritePrivateProfileString(app, var, value, file)
Exit Function
Errorcond:
msg = "A problem has occurred while updating data in your .ini file.
Please contact your system administrator"
Response = MsgBox(msg, vbOKOnly + vbInformation, "Initialization Error")
End Function