Function notes: ———————— (1) ————————————
Note: Get all the key values Truezq under a section in the specified INI file, and require the following API declaration
Note: 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
Note: Returns an array of strings
Note: invoke Example:
Note: Dim Arrclass () as String
Note: Arrclass = getinfosection ("Class", "D:\type.ini")
Public Function getinfosection (strsection As String, Strinifile as String) as String ()
Dim Strreturn as String * 32767
Dim strtmp as String
Dim nstart As Integer, nend As Integer, I As Integer
Dim Sarray () as String
Call Getprivateprofilesection (Strsection, Strreturn, Len (Strreturn), strinifile)
strtmp = Strreturn
i = 1
Do While strtmp <> ""
Nstart = nend + 1
Nend = InStr (Nstart, Strreturn, vbNullChar)
strtmp = mid$ (Strreturn, Nstart, Nend-nstart)
If Len (strtmp) > 0 Then
ReDim Preserve Sarray (1 to i)
Sarray (i) = strtmp
i = i + 1
End If
Loop
Getinfosection = Sarray
End Function
Note: ———————— (2) ————————————
Note: function: Remove the trailing space, all invalid characters in the string
Comments: Test Cases
Note: Dim Strres as String
Note: Dim Strsour as String
Comments:
Note: Strsour = "" & vbNullChar & vbNullChar & "AB CD" & vbNullChar
Note: Strres = Zqtrim (strsour)
Note: MsgBox "length =" & Len (Strsour) & "Value =111" & Strres & "222"
Public Function Zqtrim (ByVal strsour As String) as String
Dim strtmp as String
Dim Nlen as Integer
Dim I As Integer, J As Integer
Dim Strnow As String, Strvalid () As String, strnew as String
Note: Strnow current character
Note: strvalid valid characters
Note: Strnew the last generated new character
strtmp = trim$ (strsour)
Nlen = Len (strtmp)
If Nlen < 1 Then
Zqtrim = ""
Exit Function
End If
j = 0
For i = 1 to Nlen
Strnow = Mid (strtmp, I, 1) Note: read one character at a time
Note: MsgBox Asc (Strnow)
If Strnow <> vbNullChar and ASC (strnow) <> 9 Then Note: If valid, save in a valid array
ReDim Preserve Strvalid (j)
Strvalid (j) = Strnow
j = j + 1
End If
Next I
Strnew = Join (Strvalid, "") Note: Connect all valid characters
Zqtrim = trim$ (strnew) Note: Remove the trailing space in the string
End Function
Note: ———————— (3) ————————————
Note: Check that the file exists, that there is a return TRUE, or false
Public Function checkfileexist (strfile as String) as Boolean
If Dir (strfile, vbdirectory) <> "" Then
Checkfileexist = True
Else
Checkfileexist = False
End If
End Function
Note: ———————— (4) ————————————
Note: Gets the key value of a subkey below a section in the specified INI file, and requires the following API declaration
Note: public Declare Function getprivateprofilestring Lib "Kernel32" Alias _
Note: "Getprivateprofilestringa" (ByVal Lpapplicationname as String, _
Note: ByVal lpkeyname as any, ByVal Lpdefault as String, ByVal lpreturnedstring _
Comments: As String, ByVal nsize as Long, ByVal lpFileName as String) as Long
Note: Returns a string
Note: invoke Example:
Note: Dim Strrun as String
Note: Strrun = Getinivalue ("Windows", "Run", "C:\Windows\Win.ini")
Public Function Getinivalue (ByVal lpkeyname As String, ByVal StrName as String, ByVal Strinifile as String) as String
Dim strtmp as String * 255
Note: ———————— (5) ————————————
Note: Get the Windows directory, you need the following API declaration
Note: Private Declare Function getwindowsdirectory Lib "kernel32" Alias "Getwindowsdirectorya" (ByVal lpbuffer as String, BYV Al Nsize as Long) as long
Remarks: Returns a string, such as "C:\Windows", "C:\Winnt"
Note: invoke Example:
Note: Dim Strwindir as String
Note: Strwindir = Getwindir ()
Private Function Getwindir ()
Dim windir as String * 100
Call GetWindowsDirectory (windir, 100)
Getwindir = left$ (windir, InStr (windir, vbNullChar)-1)
End Function
Note: ———————— (6) ————————————
Note: Access to the Windows System directory requires the following API declaration
Note: Private Declare Function getsystemdirectory Lib "kernel32" Alias "Getsystemdirectorya" (ByVal lpbuffer as String, ByVal Nsize as long) as long
Remarks: Returns a string, such as "C:\Windows\System", "C:\Winnt\System32"
Note: invoke Example:
Note: Dim Strsysdir as String
Note: Strsysdir = Getsystemdir ()
Private Function Getsystemdir ()
Dim Strsysdir as String * 100
Call GetSystemDirectory (Strsysdir, 100)
Getsystemdir = left$ (Strsysdir, InStr (Strsysdir, vbNullChar)-1)
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.