clsini.cls
来自「一个VB实现串口通讯的经典示例.非常简明, 使用, 本人大部分通讯程序与之类同」· CLS 代码 · 共 66 行
CLS
66 行
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsIni"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_FileName As String
Public Property Get FileName() As String
FileName = m_FileName
End Property
Public Property Let FileName(ByVal sFilename As String)
m_FileName = sFilename
End Property
Public Function GetVar(ByVal sTag As String) As Variant
Dim iFH As Integer, sLine As String, sVarName As String
Dim sBuf As String, Result As Variant, iEqualPos As Integer
sBuf = Dir(m_FileName)
If m_FileName = "" Or sBuf = "" Then
Exit Function
End If
iFH = FreeFile
On Error GoTo clsIni_Read_Error
Open m_FileName For Input As #iFH
Do While Not EOF(iFH)
Input #iFH, sLine
sLine = Trim(sLine)
If sLine = "" Or Left(sLine, 1) = ";" Or Left(sLine, 1) = "#" Or Left(sLine, 1) = "'" Then GoTo clsIni_Read_Loop
iEqualPos = FindChar("=", sLine)
If iEqualPos <> 0 Then
sVarName = LCase(Trim(Left(sLine, iEqualPos - 1)))
If sVarName = LCase(sTag) Then
Result = Trim(Mid(sLine, iEqualPos + 1))
Exit Do
End If
End If
clsIni_Read_Loop:
Loop
Close #iFH
iFH = 0
clsIni_Read_Error:
If Err <> 0 Then
MsgBox "Err #" & Err.Number & " : " & Err.Description, vbOKOnly, "Error in clsIni"
End If
On Error GoTo 0
If iFH <> 0 Then Close #iFH
GetVar = Result
End Function
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?