【发布时间】:2011-07-24 08:11:33
【问题描述】:
好的,我准备通过我的 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 = 和正方形之间的值。
【问题讨论】: