www.pudn.com > Winmine.rar > Module2.bas


Attribute VB_Name = "Module2" 
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 
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 
Public AppProfileName As String 
Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefString As String) As String 
Dim ResultString As String * 1000, Temp As Integer 
Dim S As String, i As Integer 
Temp% = GetPrivateProfileString(SectionName, KeyWord, "", ResultString, 1000, AppProfileName) 
'检索关键词的值 
If Temp% > 0 Then '关键词的值不为空 
  S = "" 
  For i = 1 To 1000 
    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, ppProfileName) 
  '将缺省值写入INI文件 
  S = DefString 
End If 
GetIniS = S 
End Function 
Function GetIniN(ByVal SectionName As String, ByVal KeyWord As String, ByVal DefValue As Integer) As Integer 
Dim d As Long, S As String 
On Error GoTo cw: 
d = DefValue 
GetIniN = GetPrivateProfileInt(SectionName, KeyWord, DefValue, AppProfileName) 
If d <> DefValue Then 
  S = "" & d 
  d = WritePrivateProfileString(SectionName, KeyWord, S, AppProfileName) 
End If 
 
Exit Function 
 
cw: GetIniN = -1 
End Function 
Sub SetIniS(ByVal SectionName As String, ByVal KeyWord As String, ByVal ValStr As String) 
Dim res% 
res% = WritePrivateProfileString(SectionName, KeyWord, ValStr, AppProfileName) 
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$, AppProfileName) 
End Sub