modvariables.bas

来自「Visual Basic编写的老虎机游戏。」· BAS 代码 · 共 52 行

BAS
52
字号
Attribute VB_Name = "modVariables"
' API functions
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Public intImage(3) As Integer
Public intWinnings(10) As Integer
Public bolWin As Boolean

Public Function Sleep(ByVal lngSleep As Long)
    Dim lngSleepEnd As Long
    lngSleepEnd = GetTickCount + lngSleep
    While GetTickCount <= lngSleepEnd
        DoEvents
    Wend
End Function


Public Function RoundNumber(ByRef RoundN, _
   Optional Decimals As Integer)
    On Error Resume Next
    Dim RoundAmount As Single, Result
    'Creates powers to the decimal places
    RoundAmount = 10 ^ Decimals
    'Creates a whole number, rounds, applies decimal places
    Result = (CLng((RoundN) * RoundAmount) / RoundAmount)
    RoundN = Result
End Function


Public Function RoundToValue(ByVal nValue, _
    nCeiling As Double, Optional RoundUp As Boolean = True) _
    As Double
    
    Dim tmp As Integer
    Dim tmpVal
    If Not IsNumeric(nValue) Then Exit Function
    nValue = CDbl(nValue)
    
'Round up to a whole integer -
'Any decimal value will force a round to the next integer.
'i.e. 0.01 = 1 or 0.8 = 1

    tmpVal = ((nValue / nCeiling) + (-0.5 + (RoundUp And 1)))
    tmp = Fix(tmpVal)
    tmpVal = CInt((tmpVal - tmp) * 10 ^ 0)
    nValue = tmp + tmpVal / 10 ^ 0

'Multiply by ceiling value to set RoundtoValue
    RoundToValue = nValue * nCeiling
       
End Function

⌨️ 快捷键说明

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