7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private 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
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Private 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
Private IniFileName As String
Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, Optional ByVal DefString As String) As String
Dim ResultString As String * 144, Temp As Integer
Dim s As String, i As Integer
Temp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 144, IniFileName)
If Temp% > 0 Then
s = ""
For i = 1 To 144
If Asc(Mid$(ResultString, i, 1)) = 0 Then
Exit For
Else
s = s & Mid$(ResultString, i, 1)
End If
Next
Else
Temp% = WritePrivateProfileString(SectionName, KeyWord, DefString, IniFileName)
s = DefString
End If
GetIniS = s
End Function
Function GetIniN(ByVal SectionName As String, ByVal KeyWord As String, Optional ByVal DefValue As Integer) As Integer
Dim D As Long, s As String
D = DefValue
GetIniN = GetPrivateProfileInt(SectionName, KeyWord, DefValue, IniFileName)
If D <> DefValue Then
s = "" & D
D = WritePrivateProfileString(SectionName, KeyWord, s, IniFileName)
End If
End Function
Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String)
Dim RES%
RES% = WritePrivateProfileString(SectionName, KeyWord, ValStr, IniFileName)
End Sub
Sub SetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValInt As Integer)
Dim RES%, s$
s$ = Str$(ValInt)
RES% = WritePrivateProfileString(SectionName, KeyWord, s$, IniFileName)
End Sub
Public Property Get FileName() As Variant
FileName = IniFileName
End Property
Public Property Let FileName(ByVal vNewValue As Variant)
IniFileName = vNewValue
End Property