这是收集到的一段代码,但如何用到实例中,不知具体代码如何写?
新建一个模块,复制下面的内容
Public inipath As String
Public Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
lpKeyName As Any, ByVal lpDefault As String, ByVal lpretunedstring As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
'读INI文件
Public 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
'写INI文件
Public Function GetFromINI(Appname As String, Keyname As String, _
Filename As String) As String
Dim RetStr As String
RetStr = String(255, Chr(0))
GetFromINI = Left(RetStr, GetPrivateProfileString(Appname, ByVal Keyname, "", RetStr, Len(RetStr), Filename))
End Function
'**************************************************************
'
读INI文件函数
Public Function WriteINI(inipath As String, Appname As String, Keyname As String, value As String)
Dim stemp As String
stemp = value
Call WritePrivateProfileString(Appname, Keyname, stemp, inipath)
End Function
'**************************************************************
'
写INI文件函数
'以下为窗体中的内容,不要弄混乱了
On Error GoTo Cwcl
SerName = GetFromINI("RFYSER", "SERVER", App.Path & "\RFYPOS.ini")
'服务器名
UidName = GetFromINI("RFYSER", "UID", App.Path & "\RFYPOS.ini")
'用户名
DataName = GetFromINI("RFYSER", "DATASER", App.Path & "\RFYPOS.ini")
'数据库名
PwdName = GetFromINI("RFYSER", "PWD", App.Path & "\RFYPOS.ini")
'密码
YongHuBianma = GetFromINI("RFYSER", "PER", App.Path & "\RFYPOS.ini")
'用户编号
Cwcl:
If Err.Number <> 0 Then
MsgBox Err.Description
End
End If
'说明:GetFromINI函数的用法,参照下面INI文件,文件名为RFYPOS.INI