⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module3.bas

📁 这个源代码主要模仿了一个类似 深度操作系统安装程序中的一个软件自动安装管理器AutoIt v3
💻 BAS
字号:
Attribute VB_Name = "Module3"

'**************************************
'Windows API/Global Declarations for :Ge
'     tSectionNames
'**************************************


Public Declare Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" (ByVal lpReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'**************************************
' Name: GetSectionNames
' Description:Nifty. It reads all the se
'     ction names (e.g, "[SECTION_1]") from an
'     INI file, and returns them to you as an
'     array of strings. Uses one API call.
' By: Adam Murray
'
'
' Inputs:
'lpIniFile as string: the name of the INI file to parse;
'sDestArray() as string: the zero-based destination array of strings to hold the section titles
'
' Returns:Integer: the number of section
'     names it found.
'
'Assumes:None
'
'Side Effects:none
'This code is copyrighted and has limite
'     d warranties.
'Please see http://www.Planet-Source-Cod
'     e.com/xq/ASP/txtCodeId.23807/lngWId.1/qx
'     /vb/scripts/ShowCode.htm
'for details.
'**************************************

Private Const MAX_SECTION_STRING_LEN = 8192


Function GetSectionNames(lpIniFile As String, sDestArray() As String) As Integer
    Dim i As Integer
    Dim ch As Integer
    Dim lpTemp As String * MAX_SECTION_STRING_LEN
    Dim lpLineIn As String
    
    Call GetPrivateProfileSectionNames(lpTemp, Len(lpTemp), lpIniFile)
    
    lpTemp = Trim(lpTemp)
    lpLineIn = ""
    
    Dim iCount As Integer: iCount = 0
    Dim sections() As String
    


    For i = 1 To Len(lpTemp)
        ch = Asc(Mid$(lpTemp, i, 1))


        If ch = 0 Then


            If Len(Trim(lpLineIn)) > 0 Then
                ReDim Preserve sections(iCount) As String
                sections(iCount) = lpLineIn
                iCount = iCount + 1
            End If
            lpLineIn = ""
        Else
            lpLineIn = lpLineIn + Mid$(lpTemp, i, 1)
        End If
    Next
    
    ReDim sDestArray(iCount)
    sDestArray = sections
    
    GetSectionNames = iCount
End Function


Sub Main()
    
    Dim myArray() As String
    Dim iCount As Integer
    iCount = GetSectionNames("c:\foo.ini", myArray())
    
    Dim i As Integer
    


    For i = 0 To iCount - 1
        Debug.Print CStr(i) + ": " + myArray(i)
    Next i
    
    End
End Sub
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -