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

📄 basmisc.bas

📁 功能强大的API
💻 BAS
字号:
Attribute VB_Name = "basMisc"
'****************************************
'汉化: 小聪明       coolzm@sohu.com
'小聪明的主页VB版:  http://coolzm.533.net
'****************************************
Option Explicit

' 将给定的数Num的第bit位置1(二进制)
'
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

' 功能和SetBit相反(二进制)
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

'
'  检测给定的数Num的第bit位是否为1 (二进制)
'
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

' 把一个窗体放到屏幕中央或者放到另一个窗体的中央
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.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

' 判断给定的年是否为闰年
'
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

'
'  把一个数组中的元素的顺序随机打乱
'  你如果要写扑克游戏应该用得着---------小聪明
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 + -