Public Function loadINI(strfileName, strSection, strKey) As String
On Error GoTo err
states = GetPrivateProfileString(strSection, strKey, "", strResult, 255, strfileName)
If (states = 0) Then
MsgBox ("no read the value")
Else
loadINI = strResult
End If
Exit Function
err:
Exit Function
End Function以上是我的代码 ,可是不知道为什么就是导致vb6.0退出。
请大家帮忙,,,,,
On Error GoTo err
states = GetPrivateProfileString(strSection, strKey, "", strResult, 255, strfileName)
If (states = 0) Then
MsgBox ("no read the value")
Else
loadINI = strResult
End If
Exit Function
err:
Exit Function
End Function以上是我的代码 ,可是不知道为什么就是导致vb6.0退出。
请大家帮忙,,,,,
'这样试试?
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 pFileName As String) As LongPublic Function loadINI(strfileName, strSection, strKey) As String
On Error GoTo err
strResult = VBA.String(255, 0)
states = GetPrivateProfileString(strSection, strKey, "", strResult, 255, strfileName)
If (states = 0) Then
MsgBox ("no read the value")
Else
loadINI = strResult
End If
Exit Function
err:
Exit Function
End Function
按照你的指示我修改后果然通过了
请问这是什么原因呢?
我能定位到是 strResult 的问题。
但是我无法改正。
请问你的strResult = VBA.String(255, 0)是什么意思呢?
而定义为strResult AS NEW STRING * 255却可以正确了,这句跟你的strResult = VBA.String(255, 0)的意图是一样的啊