Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private m_filename As String = "F:TextFile.ini"
Public Function GetiniValue(ByVal lpKeyName As String, ByVal strName As String) As String
Dim strTmp As String
Dim size As Long = 50
Dim valueSize As Long
strTmp = New String(" ", 100)
valueSize = GetPrivateProfileString(lpKeyName, strName, "出错了!", strTmp, size, m_filename)
GetiniValue = Left(strTmp, valueSize)
End Function
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
'下面为INI文件内容,以这个为参考,相信你能行的,别忘了给分,
'下面为INI文件内容,以这个为参考,相信你能行的,别忘了给分,
'下面为INI文件内容,以这个为参考,相信你能行的,别忘了给分,
'下面为INI文件内容,以这个为参考,相信你能行的,别忘了给分,
[RFYSER]
SERVER=192.168.2.30
UID=sa
PER=1001
DATASER=ADK_CARD
PWD=
'上面为INI文件内容,以这个为参考,相信你能行的,别忘了给分,
GetiniValue = Left(strTmp, valueSize)
改成
GetiniValue = Left(strTmp, valueSize-1)