大家看看,两个从ini取信息的函数,哪个好呀?(第一个有问题吗)
大家看看,两个从ini取信息的函数,哪个好呀? 以下两个函数都是网上找的,第一个说不好来处,第二个是老马的代码(从他的论坛下的)
我想问问哪种更好些,第一种代码少,简洁很多,
第二个代码,代码量大,主要是因为多了一个循环截尾的操作。因为我现在用的是第一种代码,可是看到很多网友都在用第二种代码,我不知道为什么,为何在用循环呢?
是不是第一种操作的字符截尾操作有问题呀?
Public Function GetIniKey(strSection As String, strKey As String) As String
On Error GoTo errhandle
Dim strResult As String * 255 '固定255长度
Dim lngRet As Long
lngRet = GetPrivateProfileString(strSection, strKey, "", strResult, Len(strResult), strINI)
GetIniKey = Left(strResult, InStr(strResult, Chr(0)) - 1)
Exit Function
errhandle:
GetIniKey = ""
End Function
Function GetIniS(ByVal SectionName As String, ByVal KeyWord As String, 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