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

📄 basmisc.bas

📁 常用基本函数库,也许你需要的正在其中!如果不做程序
💻 BAS
字号:
Attribute VB_Name = "basMisc"
Option Explicit
' Misc. functions.

'
'  Sets a given bit in num
'
Public Function SetBit(Num As Long, ByVal bit As Long) As Long
   If bit = 31 Then
      Num = &H80000000 Or Num
   Else
      Num = (2 ^ bit) Or Num
   End If
   
   SetBit = Num
End Function

'
'  clears a given bit in num
'
Public Function ClearBit(Num As Long, ByVal bit As Long) As Long
   If bit = 31 Then
      Num = &H7FFFFFFF And Num
   Else
      Num = ((2 ^ bit) Xor &HFFFFFFFF) And Num
   End If
   
   ClearBit = Num
End Function

'
'  Test if bit 0 to bit 31 is set.
'
Public Function IsBitSet(ByVal Num As Long, ByVal bit As Long) As Boolean
   IsBitSet = False
   
   If bit = 31 Then
      If Num And &H80000000 Then
         IsBitSet = True
      End If
   Else
      If Num And (2 ^ bit) Then
         IsBitSet = True
      End If
   End If
End Function

' Centers a form relative to the screen or
' another form
Public Sub CenterForm(f As Form, Optional f2 As Variant)
   If IsMissing(f2) Then
      f.Move (Screen.Width - f.Width) / 2, _
             (Screen.Height - f.Height) / 2
   Else
      ' If f is an MDI child in a MDI parent then
      ' center f within the parent.
      If f.MDIChild And Not f2.MDIChild Then
            f.Move ((f2.Width - f.Width) / 2), _
            ((f2.Height - f.Height) / 2)
      Else
         f.Move ((f2.Width - f.Width) / 2) + f2.Left, _
                ((f2.Height - f.Height) / 2) + f2.Top
      End If
   End If
End Sub







Public Function IsEven(ByVal i As Long) As Boolean
   IsEven = Not -(i And 1)
End Function






'
'  Returns true if the year is a leap year.
'     yr is either a date or an integer
'
Public Function IsLeapYear(yr As Variant) As Boolean
   If VarType(yr) = vbDate Then
      IsLeapYear = (Day(DateSerial(Year(yr), 2, 29)) = 29)
   Else
      IsLeapYear = (Day(DateSerial(yr, 2, 29)) = 29)
   End If
End Function

Public Function IsOdd(ByVal i As Long) As Boolean
   IsOdd = -(i And 1)
End Function

'
'  Scrambles the order of elements in an array.
'
Public Sub ShuffleArray(ByRef vArray As Variant, Optional startIndex As Variant, Optional endIndex As Variant)
    Dim i As Long
    Dim rndIndex As Long
    Dim Temp As Variant
    
    If IsMissing(startIndex) Then
       startIndex = LBound(vArray)
    End If
    
    If IsMissing(endIndex) Then
       endIndex = UBound(vArray)
    End If

    For i = startIndex To endIndex
        rndIndex = Int((endIndex - startIndex + 1) * Rnd() + startIndex)

        Temp = vArray(i)
        vArray(i) = vArray(rndIndex)
        vArray(rndIndex) = Temp
    Next i
End Sub

⌨️ 快捷键说明

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