'
'* Function: Use vbs to read all values under the specified node in the INI file.
'* Input parameter: inipath: INI file address
'* Initypes: The INI file contains values between "[" and "]".
'* Return value: array composed of the values of the field found
'* Prepared by: chenyb
'* Prepared on:
'* Other Instructions: The following is only a method, and the specific problem is modified.
'
Function vbsgetinifields (inipath, initypes)
Const forreading = 1' defines Constants
'Fso object, Text object, next data variable, string SEARCH location
Dim objfso, objtextfile, strnextline, intlinefinder
Dim State 'specifies whether the field is found in the matched initypes
Dim TMP 'temporary storage string
Dim typelist 'string list after string segmentation
Dim rsstr 'function Return Value
Set objfso = Createobject ("scripting. FileSystemObject") 'to create a FSO object
Set objtextfile = objfso. opentextfile (inipath, forreading) 'open the document
Do until objtextfile. atendofstream 'traverses each row
Strnextline = objtextfile. readline' read a row of data
'If you have found initypes and "[]", it indicates that the field is not found.
If instr (strnextline, "[") <> 0 and instr (strnextline, "]") <> 0 then
If State = 1 then
Exit do
End if
TMP = trim (mid (TRIM (strnextline), instr (strnextline, "[") + 1, Len (initypes )))
If TMP = trim (initypes) then' finds initypes
State = 1
Strnextline = objtextfile. Readline
End if
End if
If State = 1 then
Intlinefinder = instr (strnextline, "=") 'search for "=" in the string"
If intlinefinder <> 0 then', if "=" is found"
Typelist = Split (strnextline, "=") 'splits the string
Rsstr = rsstr & "," "& typelist (1) &" 'value assignment
End if
End if
Loop
Objtextfile. Close 'Close the document
Execute "vbsgetinifields = array (" & right (rsstr, Len (rsstr)-1) & ")" 'Return Value
End Function
************************** ****
Dim t
T = vbsgetinifields ("Public Prosecution. ini", "including vbs ")
Msgbox ubound (t)
Msgbox T (0)
Msgbox T (1)
'*************************************** **********