好的,所以我有这些函数我想通过我的vba代码使用。 它可能与vbs一样。
这是功能
'declarations for working with Ini files
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias _
"GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
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
'// INI CONTROLLING PROCEDURES
'reads an Ini string
Public Function ReadIni(Filename As String, Section As String, Key As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, Filename)
ReadIni = Left(RetVal, v + 0)
End Function
'reads an Ini section
Public Function ReadIniSection(Filename As String, Section As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(Section, RetVal, 255, Filename)
ReadIniSection = Left(RetVal, v + 0)
End Function
如何使用它来创建一个基本上允许我只指定我想要查看的部分的函数,然后找到该部分中的每个ini字符串并将其放入数组并返回该数组以便我可以执行用它循环?
编辑:我看到ReadIniSection返回一个巨大的字符串中的所有键。 意思是,我需要拆分它。
ReadIniSection返回如下所示的内容: “Fornavn = FORNAVN [] Etternavn = ETTERNAVN”等等。[]中间没有括号,它是一个正方形。可能是一些它无法识别的角色。所以我想我应该通过一个分割命令运行它,它取一个a =和square之间的值。
答案 0 :(得分:2)
看看这是否有帮助 - 拆分nullchar \ 0:
Private Sub ListIniSectionLines()
Dim S As String: S = ReadIniSection("c:\windows\win.ini", "MAIL")
Dim vLines As Variant: vLines = Split(S, Chr$(0))
Dim vLine As Variant
For Each vLine In vLines
Debug.Print vLine
Next vLine
End Sub