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

📄 moduleini.bas

📁 完整的VB和单片机系统连接的源代码
💻 BAS
字号:
Attribute VB_Name = "ModuleIni"





'----------------------------------------------------------------------

'使用ini文件
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
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
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





'同名.ini文件的Interface项
Public Function GetIniInterface(KeyName$, KeyValue$, DefaultKeyValue$) As String
    GetIniInterface = GetIniString("Interface", KeyName$, KeyValue$, DefaultKeyValue$)
End Function
Public Function SetIniInterface(KeyName$, KeyValue$) As String
    SetIniString "Interface", KeyName$, KeyValue$
End Function


'同名.ini文件
Public Function GetIniString(KeySection$, KeyName$, KeyValue$, DefaultKeyValue$) As String
    Dim fs As String
    fs = fnIniFile
    GetIniString = ReadIniFile(fs, KeySection$, KeyName$, KeyValue$, DefaultKeyValue$)
End Function
Public Function SetIniString(KeySection$, KeyName$, KeyValue$) As String
    Dim fs As String, KeyValue2$
    fs = fnIniFile
    WriteIniFile fs, KeySection$, KeyName$, Trim(KeyValue$)
End Function





'任意ini文件
Public Function ReadIniFile(FileName$, KeySection$, KeyName$, KeyValue$, DefaultKeyValue$) As String
    Dim fs As String, KV$, KV2$
    KV$ = String(256, 0)
    GetPrivateProfileString KeySection$, KeyName$, "?", KV$, 256, FileName$
    KV2$ = Left(KV$, InStr(1, KV$, Chr(0), vbBinaryCompare) - 1)
    If KV2$ = "?" Then
        KV$ = DefaultKeyValue$
    Else
        KV$ = KV2$
    End If
    ReadIniFile = KV$
End Function
Public Function WriteIniFile(FileName$, KeySection$, KeyName$, KeyValue$) As String
    Dim KV$
    KV$ = Trim(KeyValue$)
    WritePrivateProfileString KeySection$, KeyName$, KV$, FileName$
End Function

'检测文件是否存在
Function FileExists%(FileName$)
Dim f%
   On Error Resume Next
   f% = FreeFile
   Open FileName$ For Input As #f%
   Close #f%
   FileExists% = Not (Err <> 0)
End Function



⌨️ 快捷键说明

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