문제

나는 VBA Excel과 약간의 주요 요인화를하려고 노력하고 있으며 long 데이터 형식 -

런타임 오류 6 오버 플로우

이 문제를 해결하고 여전히 VBA 내에 머물 수있는 방법이 있습니까? 분명한 것은 또 다른 더 적절한 프로그래밍 언어를 사용하는 것임을 알고 있습니다.


랜스의 해결책 지금까지 작동하여 지금은 큰 숫자를 변수에 넣을 수 있습니다. 그러나 내가 적용하려고 할 때 MOD 기능 - Bignumber MOD 2, 예를 들어 - 오류 메시지가 여전히 실패합니다.

런타임 오류 6 오버 플로우

도움이 되었습니까?

해결책

Mod는 작동하기 전에 소수점 유형을 오랫동안 변환하려고합니다. 소수점 유형에 대해 자신의 MOD 기능을 작성해야 할 수도 있습니다. 당신은 이것을 시도 할 수 있습니다 :

r = A - Int(A / B) * B

여기서 A & B는 변형 변수의 소수 하위 유형이며 R은 (필요에 따라) 크게 클 수 있지만, 오랫동안 테스트했습니다.

다른 팁

십진 데이터 유형을 사용할 수 있습니다. Google의 빠른 힌트 : http://www.ozgrid.com/vba/convert-to-decimal.htm

이것은 내 decimals.cls (vb6)입니다.

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Decimals"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

'local variable(s) to hold property value(s)
Private mvarDec As Variant 'local copy

Public Property Let Dec(ByVal vData As Variant)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Dec = 5
    mvarDec = CDec(vData)
End Property

Public Property Get Dec() As Variant
Attribute Dec.VB_UserMemId = 0
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Dec
    Dec = CDec(mvarDec)
End Property

그리고 이것은 테스트 프로그램입니다. 클래스가 설정되었으므로 Get and Let의 .dec ()로 자격이 없습니다.

Dim dec1 As New Std.Decimals
Dim dec2 As New Std.Decimals
Dim dec3 As New Std.Decimals
Dim modulus As New Std.Decimals

Sub main()
    dec1 = "1000.000000001"
    dec2 = "1000.00000000000001"
    dec3 = dec1 + dec2
    Debug.Print dec1
    Debug.Print dec2
    Debug.Print dec3
    Debug.Print dec3 * dec3
    Debug.Print dec3 / 10
    Debug.Print dec3 / 100
    Debug.Print Sqr(dec3)
    modulus = dec1 - Int(dec1 / dec2) * dec2
    Debug.Print modulus
End Sub

그리고 샘플 실행

 1000.000000001 
 1000.00000000000001 
 2000.00000000100001 
 4000000.000004000040000001 
 200.000000000100001 
 20.0000000000100001 
 44.721359550007 
 0.00000000099999 
 1000.000000001 
 1000.00000000000001 
 2000.00000000100001 
 4000000.000004000040000001 
 200.000000000100001 
 20.0000000000100001 
 44.721359550007 
 0.00000000099999 

다음은 임의로 많은 숫자 (예 : 100 자 길이)를 곱하기위한 "큰 곱하기"루틴입니다. 그것은 문자열 인 입력 번호를 7 자리 숫자로 나누어서 작동합니다 (그러면 결과를 두 배로 곱할 수 있기 때문에).

예를 들어 Bigmultiply ( "1934567803945969696433", "448383838211678") = 8674289372323389542267888888886480754474

Function BigMultiply(ByVal s1 As String, ByVal s2 As String) As String

Dim x As Long
x = 7

Dim n1 As Long, n2 As Long, n As Long
n1 = Int(Len(s1) / x + 0.999999)
n2 = Int(Len(s2) / x + 0.999999)
n = n1 + n2

Dim i As Long, j As Long
ReDim za1(n1) As Double
i = Len(s1) Mod x
If i = 0 Then i = x
za1(1) = Left(s1, i)
i = i + 1
For j = 2 To n1
 za1(j) = Mid(s1, i, x)
 i = i + x
Next j

ReDim za2(n2) As Double
i = Len(s2) Mod x
If i = 0 Then i = x
za2(1) = Left(s2, i)
i = i + 1
For j = 2 To n2
 za2(j) = Mid(s2, i, x)
 i = i + x
Next j

ReDim z(n) As Double
Dim u1 As Long, u2 As Long
Dim e As String
e = String(x, "0")

For u1 = 1 To n1
 i = u1
 For u2 = 1 To n2
   i = i + 1
   z(i) = z(i) + za1(u1) * za2(u2)
 Next u2
Next u1

Dim s As String, y As Double, w As Double, m As Long
m = n * x
s = String(m, "0")
y = 10 ^ x
For i = n To 1 Step -1
 w = Int(z(i) / y)
 Mid(s, i * x - x + 1, x) = Format(z(i) - w * y, e)
 z(i - 1) = z(i - 1) + w
Next i
'truncate leading zeros
For i = 1 To m
 If Mid$(s, i, 1) <> "0" Then Exit For
Next i
If i > m Then
 BigMultiply = ""
Else
 BigMultiply = Mid$(s, i)
End If

End Function
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top