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

📄 lngnum.cls

📁 可以对无限长度的整数进行加、减
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "LngNum"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Num1() As Integer, Num1L As Integer, Num2() As Integer, Num2L As Integer, _
Result() As Integer, ResultL As Integer

Public Sub Plus()
    Dim i As Integer, n1 As Integer, n2 As Integer
    
    ResultL = Max(Num1L, Num2L)
    ReDim Result(ResultL)
    For i = 1 To ResultL
        If i <= Num1L Then n1 = Num1(i) Else n1 = 0
        If i <= Num2L Then n2 = Num2(i) Else n2 = 0
        Result(i) = n1 + n2
    Next
    FormatRlt
End Sub

Private Sub FormatRlt()
    Dim i As Integer, R As Integer, fh As Integer
    
    i = ResultL
    Do
        R = Result(i)
        i = i - 1
    Loop While R = 0 And i > 0
    If i = 0 Then Exit Sub
    If R < 0 Then
        fh = -1
        For i = 1 To ResultL
            Result(i) = -Result(i)
        Next
    End If
    For i = 1 To ResultL - 1
        If Result(i) >= 10000 Then
            Result(i) = Result(i) - 10000
            Result(i + 1) = Result(i + 1) + 1
        End If
        If Result(i) <= 0 Then
            Result(i) = Result(i) + 10000
            Result(i + 1) = Result(i + 1) - 1
        End If
        If Result(i) <= 0 Then
            Result(i) = Result(i) + 10000
            Result(i + 1) = Result(i + 1) - 1
        End If
    Next
    If fh = -1 Then
        For i = 1 To ResultL
            Result(i) = -Result(i)
        Next
    End If
End Sub


Private Function Min(a As Integer, b As Integer)
    Min = a
    If b < Min Then Min = b
End Function
Private Function Max(a As Integer, b As Integer)
    Max = a
    If b > Max Then Max = b
End Function


Public Property Get Number1() As String
    On Error Resume Next
    Dim i As Integer, fh As Integer
    
    If Num1L = 0 Then
        Number1 = "0"
        Exit Property
    End If
    If Num1(1) < 0 Then
        fh = -1
    End If
    For i = 1 To Num1L
        Number1 = Format(Abs(Num1(i)), "0000") & Number1
    Next
    Do While Left(Number1, 1) = "0" And Len(Number1) > 1
        Number1 = Right(Number1, Len(Number1) - 1)
    Loop
    If fh = -1 Then
        Number1 = "-" & Number1
    End If
End Property

Public Property Let Number1(ByVal Value As String)
    On Error Resume Next
    Dim modd As String, fh As Integer, i As Integer
    
    fh = 1
    If Left(Value, 1) = "-" Then
        fh = -1
        Value = Right(Value, Len(Value) - 1)
    End If
    ReDim Num1(1)
    If Value = "0" Then
        Num1L = 0
        Exit Property
    End If
    Do While Value <> ""
        modd = Right(Value, Min(4, Len(Value)))
        i = i + 1
        ReDim Preserve Num1(i)
        Num1(i) = Val(modd)
        Value = Left(Value, Max(Len(Value) - 4, 0))
    Loop
    Num1L = i
    If fh = -1 Then
        For i = i To 1 Step -1
            Num1(i) = -Num1(i)
        Next
    End If
End Property
Public Property Get Number2() As String
    On Error Resume Next
    Dim i As Integer, fh As Integer
    
    If Num2L = 0 Then
        Number2 = "0"
        Exit Property
    End If
    If Num2(1) < 0 Then
        fh = -1
    End If
    For i = 1 To Num2L
        Number2 = Format(Abs(Num2(i)), "0000") & Number2
    Next
    Do While Left(Number2, 1) = "0" And Len(Number2) > 1
        Number2 = Right(Number2, Len(Number2) - 1)
    Loop
    If fh = -1 Then
        Number2 = "-" & Number2
    End If
End Property

Public Property Get ResultGet() As String
    On Error Resume Next
    Dim i As Integer, fh As Integer
    
    If ResultL = 0 Then
        ResultGet = "0"
        Exit Property
    End If
    If Result(1) < 0 Then
        fh = -1
    End If
    For i = 1 To ResultL
        ResultGet = Format(Abs(Result(i)), "0000") & ResultGet
    Next
    Do While Left(ResultGet, 1) = "0" And Len(ResultGet) > 1
        ResultGet = Right(ResultGet, Len(ResultGet) - 1)
    Loop
    If fh = -1 Then
        ResultGet = "-" & ResultGet
    End If
End Property

Public Property Let Number2(ByVal Value As String)
    On Error Resume Next
    Dim modd As String, fh As Integer, i As Integer
    
    fh = 1
    If Left(Value, 1) = "-" Then
        fh = -1
        Value = Right(Value, Len(Value) - 1)
    End If
    ReDim Num2(1)
    If Value = "0" Then
        Num2L = 0
        Exit Property
    End If
    Do While Value <> ""
        modd = Right(Value, Min(4, Len(Value)))
        i = i + 1
        ReDim Preserve Num2(i)
        Num2(i) = Val(modd)
        Value = Left(Value, Max(Len(Value) - 4, 0))
    Loop
    Num2L = i
    If fh = -1 Then
        For i = i To 1 Step -1
            Num2(i) = -Num2(i)
        Next
    End If
End Property

Public Sub Subtraction()
    Dim i As Integer
    
    For i = 1 To Num2L
        Num2(i) = -Num2(i)
    Next
    Plus
End Sub

Public Sub Multiply()
    Dim Num1C As Integer, Num2C As Integer, fh As Integer, i As Integer
    Dim Rtn() As Long
    
    ResultL = Num1L + Num2L + 2
    ReDim Rtn(ResultL)
    ReDim Result(ResultL)
    fh = 1
    
    i = Num1L
    Do
        R = Num1(i)
        i = i - 1
    Loop While R = 0 And i > 0
    If R < 0 And i > 0 Then
        fh = -fh
        For i = 1 To Num1L
            Num1(i) = -Num1(i)
        Next
    End If
    
    i = Num2L
    Do
        R = Num2(i)
        i = i - 1
    Loop While R = 0 And i > 0
    If R < 0 And i > 0 Then
        fh = -fh
        For i = 1 To Num2L
            Num2(i) = -Num2(i)
        Next
    End If
    For Num1C = 1 To Num1L
        For Num2C = 1 To Num2L
            Rtn(Num1C + Num2C - 1) = Rtn(Num1C + Num2C - 1) + CLng(Num1(Num1C)) * CLng(Num2(Num2C))
        Next
    Next
    For i = 1 To ResultL - 1
        Rtn(i + 1) = Rtn(i + 1) + Rtn(i) \ 10000
        Rtn(i) = Rtn(i) Mod 10000
    Next
    For i = 1 To ResultL
        Result(i) = fh * CInt(Rtn(i))
    Next
End Sub

⌨️ 快捷键说明

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