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

📄 const.bas

📁 用vb实现在线考试系统
💻 BAS
字号:
Attribute VB_Name = "声明常量"


' 各通道的视频状态
Public gStatusOfVideo(1 To 64) As Integer

'4 画面显示时记录具体显示的那四个通道编号
Public gWhichToShow4(1 To 4) As Integer


'9 画面显示时记录具体显示的那九个通道编号
Public gWhichToShow9(1 To 9) As Integer

Public fso As New FileSystemObject

''''''
Public ErrorMsg As String
Private IniFileName As String
''''


' 读Ini文件
Public 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
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
' 写Ini文件
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As String, ByVal lpFileName As String) As Long

' 获得毫秒级时间
Public Declare Function timeGetTime Lib "winmm.dll" () As Long


'16 画面显示时记录具体显示的那16个通道编

Public gWhichToShow16(1 To 16) As Integer

Public HandShow(0 To 64) As Integer

' 获取程序运行路径
Public Function gGetAppPath() As String
    gGetAppPath = ConvertPath(App.Path)
End Function

' 获取Ini文件的存放路径
Public Function gGetIniPath() As String
    gGetIniPath = gGetAppPath & "Ini\"
End Function

'调整路径字符串,使之以\符号结尾
Public Function ConvertPath(ByVal sPath As String) As String
    If right(sPath, 1) = "\" Then
        ConvertPath = sPath
    Else
        ConvertPath = sPath & "\"
    End If
End Function
'****************************************************************************************************
'功能:读出 INI 文件的信息
'输入:
'     iniFile       String  INI的文件名
'     Section       String  INI文件中的段落
'     Key           String  INI文件中的关键字
'     defValue      String  INI文件中的值,输入时取空值
'输出:
'     GetIni        String  取得的INI文件中的值
'*****************************************************************************************************
Public Function GetIni(ByRef iniFile As String, ByVal Section As String, ByVal key As String, ByVal defValue _
                         As String) As String
                         
        Dim sTemp As String * 256
        Dim nLen As Integer
        
        sTemp = Space$(256)  '如果值为空,那么 nLen将返回0,否则返回关键字的值的长度
        nLen = GetPrivateProfileString(Section, key, defValue, sTemp, 255, gGetIniPath & "\" & iniFile)
        GetIni = left$(sTemp, nLen)
        
End Function

'**********************************************************************************************************
'功能: 向 INI 文件写入信息
'输入:
'     iniFile       String  INI的文件名
'     Section       String  INI文件中的段落
'     Key           String  INI文件中的关键字
'     Value         String  INI文件中的值,可以是数字字符串
'输出: 无
'*********************************************************************************************************
Public Sub WriteIni(ByRef iniFile As String, ByVal Section As String, ByVal key As String, ByVal Value As String)
        
       Dim X As Long, Buff As String * 256, i As Integer
       
       'INI 文件中的字符串必须以字符CHr(0) 结尾
       Buff = Value + Chr(0)
       X = WritePrivateProfileString(Section, key, Buff, gGetIniPath & "\" & iniFile)

End Sub
                         


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
''
' 延迟
Public Sub gDelay(ByVal ms As Long)
Dim t As Long

    t = timeGetTime + ms
    Do While timeGetTime < t
        DoEvents
    Loop
End Sub


Public Function ReadInt(Section As String, key As String) As Long
    Dim ReturnLng As Long
    ReadInt = 0
    ReturnLng = GetPrivateProfileInt(Section, key, 0, IniFileName)
    If ReturnLng = 0 Then
        ReturnLng = GetPrivateProfileInt(Section, key, 1, IniFileName)
        If ReturnLng = 1 Then
            ErrorMsg = "不能读取"
            Exit Function
        End If
    End If
    ReadInt = ReturnLng
End Function

Public Function ReadString(Section As String, key As String, Size As Long) As String
    Dim ReturnStr As String
    Dim ReturnLng As Long
    ReadString = vbNullString
    If NoIniFile() Then
        Exit Function
    End If
    ReturnStr = Space(Size)
    ReturnLng = GetPrivateProfileString(Section, key, vbNullString, ReturnStr, Size, IniFileName)
    ReadString = left(ReturnStr, ReturnLng)
End Function

Public Function WriteString(Section As String, key As String, Value As String) As Boolean
    WriteString = False
    If NoIniFile() Then
        Exit Function
    End If
    If WritePrivateProfileString(Section, key, Value, IniFileName) = 0 Then
        ErrorMsg = "写入失败"
        Exit Function
    End If
    WriteString = True
End Function

Private Function NoIniFile() As Boolean
    NoIniFile = True
    If IniFileName = vbNullString Then
        ErrorMsg = "没有指定 INI 文件"
        Exit Function
    End If
    ErrorMsg = vbNullString
    NoIniFile = False
End Function

Public Sub SpecifyIni(FilePathName)
    IniFileName = Trim(FilePathName)
End Sub

Private Sub Class_Initialize()
    IniFileName = vbNullString
    ErrorMsg = vbNullString
End Sub



⌨️ 快捷键说明

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