- 积分
- 12459
- 明经币
- 个
- 注册时间
- 2003-5-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
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
Public Function ReadIni(ByVal file As String, ByVal section As String, _ ByVal key As String, ByVal default As String) As String Dim x As Long Dim sSection As String, sEntry As String, sDefault As String Dim sRetBuf As String, iLenBuf As Integer, sFileName As String
'Six arguments sSection$ = section sEntry$ = key sDefault$ = default sRetBuf$ = String$(256, 0) '256 null character iLenBuf% = Len(sRetBuf$) sFileName$ = file 'function will return a value of 12 in this case x = GetPrivateProfileString(sSection$, sEntry$, sDefault$, sRetBuf$, iLenBuf%, sFileName$) 'sValue$ will contain the string 'PACKARD BELL' sValue$ = Left$(sRetBuf$, x) 'return value ReadIni = sValue$ End Function
Sub Test_ReadIni() MsgBox ReadIni("d:\test.ini", "TEST", "2", "null") End Sub
文件d:\test.ini的内容:
[test] 1=hello 2=world 3=!
|
|