VBA operations on INI files

Source: Internet
Author: User
Tags rtrim

Set (. ini) when there are too many rows.

You can use these two methods to save them.Joint Venture,When there is a lack of legal support, there is a lack of legal support.Please wait, set (. ini) Please try again later, so that many users may think twice about it.

When there is no such problem, you can save the following parameters: VB/VBA when there is no such problem ,. ini has been released successfully.Too many other usersZookeeper, and zookeeper were used to set (. ini) zookeeper, Zookeeper, and zookeeper.

'Ini has already been used
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA "_
(ByVal lpApplicationName As String, ByVal lpKeyName As String ,_
ByVal nDefault 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
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 GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA "_
(ByVal lpReturnedString As String ,_
ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA "_
(ByVal lpApplicationName As String, ByVal lpKeyName As Any ,_
ByVal lpString As Any, ByVal lpFileName As String) As Long
'@ (F)
'
'The function: Obtain the parameter value in the text Column
'
'Return character: gets the character column.
'
'Number of arguments: ARG1-API marker number comment text Column
'Arg2-character terminal character... the specified parameter vbNullChar
'
'Machine enable annotation: API token used to parse the character column (Null text character terminal fixed length ).
'Vb ← use the する text column (which can be long) ← to obtain the する
'
'Exam:
'
Public Function pGetStringFromAPI (strApiString As String ,_
Optional ByVal strEndChar As String = vbNullChar) As String
Dim intPos As Integer

IntPos = InStr (1, strApiString, strEndChar)
If intPos> 0 Then
PGetStringFromAPI = Left (strApiString, intPos-1)
Else
PGetStringFromAPI = strApiString
End If
End Function
'@ (F)
'
'The device power: INI has been successfully obtained.
'
'Failback sequence: INI has already been used when setting sequence (when not set, ARG3 has already been used to return sequence)
'
'Number of arguments: ARG1-maximum number of arguments allowed
'Arg2-Zookeeper name
'Arg3-initial deployment
'Arg4-INI has been successfully named
'
'The device specification: INI has already been used when it is used when the number of users has been reached and the number of users has been reached.
'
'Exam:
'
Public Function pGetIniNum (ByVal strSection As String, ByVal strKey As String, ByVal lngInit As Long ,_
ByVal strIniFile As String) As Long
PGetIniNum = GetPrivateProfileInt (ByVal strSection & String $ (128, vbNullChar ),_
ByVal strKey & String $ (128, vbNullChar ),_
ByVal lngInit ,_
ByVal strIniFile & String $ (128, vbNullChar ))
End Function
'@ (F)
'
'The system performance: INI has been successfully obtained.
'
'Failback sequence: INI has already been used when setting sequence (when not set, ARG3 has already been used to return sequence)
'
'Number of arguments: ARG1-maximum number of arguments allowed
'Arg2-Zookeeper name
'Arg3-initial deployment
'Arg4-INI has been successfully named
'
'The device identifier: INI has been used when the token should be obtained when the text column is successfully written or written.
'
'Exam:
'
Public Function pGetIniString (ByVal strSection As String, ByVal strKey As String, ByVal strInit As String ,_
ByVal strIniFile As String) As String
Dim strGetBuffer As String * 2048

Call GetPrivateProfileString (ByVal strSection & String $ (128, vbNullChar ),_
ByVal strKey & String $ (128, vbNullChar ),_
ByVal strInit & String $ (128, vbNullChar ),_
StrGetBuffer, ByVal LenB (strGetBuffer)/2 ,_
ByVal strIniFile & String $ (128, vbNullChar ))
PGetIniString = pGetStringFromAPI (strGetBuffer)
End Function
'@ (F)
'
'The system performance: INI has been successfully obtained.
'
'Return partition: INI internal partition Section name allocation
'
'Number of arguments: ARG1-INI contains invalid arguments using the name
'
'The Machine Vision: INI has already been used when it comes to artificial intelligence. When it comes to artificial intelligence, the entire industry has been completed.
'
'Exam: How can I perform this during the Section? When I receive a Null packet, I will return it to the department.
'
Public Function pGetIniSectionNames (ByVal strIniFile As String) As Variant
Dim strGetBuffer As String * 32767
Dim strWkString As String

Call GetPrivateProfileSectionNames (strGetBuffer, ByVal LenB (strGetBuffer)/2 ,_
ByVal strIniFile & String $ (128, vbNullChar ))
StrWkString = pGetStringFromAPI (strGetBuffer, String $ (2, vbNullChar ))
If strWkString = vbNullChar Or strWkString = "" Then
PGetIniSectionNames = Null
Else
PGetIniSectionNames = Split (strWkString, vbNullChar)
End If
End Function
'@ (F)
'
'The system performance: INI has been fully obtained.
'
'Return partition: INI contains multiple partition contents... including partition, and partition allocation.
'
'Number of arguments: ARG1-maximum number of arguments allowed
'Arg2-INI has been successfully named
'
'The Machine Vision: INI has already been used when it comes to artificial intelligence. When it comes to artificial intelligence, the entire industry has been completed.
'
'Exam: How can I perform this during the Section? When I receive a Null packet, I will return it to the department.
'
Public Function pGetIniSection (ByVal strSection As String ,_
ByVal strIniFile As String) As Variant
Dim strGetBuffer As String * 32767
Dim strWkString As String
Dim varSectionItem As Variant
Dim varKeyAndValue As Variant
Dim lngIdx As Long
Dim lngPosEq As Long
Dim lngPosComment As Long

Call GetPrivateProfileSection (ByVal strSection & String $ (128, vbNullChar ),_
StrGetBuffer, ByVal LenB (strGetBuffer)/2 ,_
ByVal strIniFile & String $ (128, vbNullChar ))
StrWkString = pGetStringFromAPI (strGetBuffer, String $ (2, vbNullChar ))
If strWkString = vbNullChar Or strWkString = "" Then
PGetIniSection = Null
Else
VarSectionItem = Split (strWkString, vbNullChar)
ReDim varKeyAndValue (0 To (UBound (varSectionItem)-LBound (varSectionItem) * 2 + 1)
For lngIdx = LBound (varSectionItem) To UBound (varSectionItem)
LngPosEq = InStr (varSectionItem (lngIdx), "= ")
If lngPosEq = 0 Then
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2) = varSectionItem (lngIdx)
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1) = ""
Else
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2) = Left (varSectionItem (lngIdx), lngPosEq-1)
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1) = Mid (varSectionItem (lngIdx), lngPosEq + 1)
End If
LngPosComment = InStr (varKeyAndValue (lngIdx-LBound (varSectionItem) * 2 ),";")
If lngPosComment> 0 Then
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2) = _
RTrim (Left (varKeyAndValue (lngIdx-LBound (varSectionItem) * 2), lngPosComment-1 ))
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1) = ""
End If
LngPosComment = InStr (varKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1 ),";")
If lngPosComment> 0 Then
VarKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1) = _
RTrim (Left (varKeyAndValue (lngIdx-LBound (varSectionItem) * 2 + 1), lngPosComment-1 ))
End If
Next lngIdx
PGetIniSection = varKeyAndValue
End If
End Function
'@ (F)
'
'The system performance: INI has been written into the text column.
'
'Back to Success success: True-success, False-loss of success
'
'Number of arguments: ARG1-maximum number of arguments allowed
'Arg2-Zookeeper name
'Arg3-text column collate
'Arg4-INI has been successfully named
'
'The host indicator: INI has been used when the parameter variable was used. When the variable was used, the variable character text column was written.
'
'Exam:
'
Public Function pSetIniString (ByVal strSection As String, ByVal strKey As String, ByVal strValue As String ,_
ByVal strIniFile As String) As Boolean
PSetIniString = CBool (WritePrivateProfileString (ByVal strSection & String $ (128, vbNullChar ),_
ByVal strKey & String $ (128, vbNullChar ),_
ByVal strValue & String $ (128, vbNullChar ),_
ByVal strIniFile & String $ (128, vbNullChar )))
End Function
'@ (F)
'
'The device power: INI has been removed successfully.
'
'Back to Success success: True-success, False-loss of success
'
'Number of arguments: ARG1-maximum number of arguments allowed
'Arg2-Zookeeper name
'Arg3-INI has been successfully named
'
'The Machine Vision: INI has been used when it should be used when it has been deleted
'
'Exam:
'
Public Function pDeleteIniKey (ByVal strSection As String, ByVal strKey As String ,_
ByVal strIniFile As String) As Boolean
PDeleteIniKey = CBool (WritePrivateProfileString (ByVal strSection & String $ (128, vbNullChar ),_
ByVal strKey & String $ (128, vbNullChar ),_
ByVal vbNullString ,_
ByVal strIniFile & String $ (128, vbNullChar )))
End Function

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.