Vbs obtains the values of all fields in a node of the ini configuration file.

Source: Internet
Author: User

'
'* 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)
'*************************************** **********

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.