Nije upalilo imam nesto sto bi moglo da pa cu ga i postaviti ovdje, vidite znali itko sta to znaci. Kreator tvrdi da može operisati sa beskonačno velikim brojevima, gotovo beskonačno velikim.
Pogledajte zna li iko kako ovo funkcioniše i ako zna molim vas da mi to rastumaći jer sam ja stvarno početnik i samo mali dio ovoga mi je jasan, pa evo :
Code:
'I created this code because I found that sometimes
'an unwated overflow error would occur. So I coded
'this, this supports Adding, Subtracting,
'Multiplication and Division however at the moment this doesn't
'support decimals. This code was also designed for maximum speed
'with minimal errors. (Hopefully none, although I realy should
'have put error handling in, mabey next version). This also has support
'for negative numbers and if you have a look at this code the
'Adding and Subtrating can depend on eachother. As you may
'notice I try and avoid using the full number. Hope this helps
'at least someone out there. :)
Const MaxLen As Long = 1000
'The constand 'MaxLen' is just the max length of any
'number to be processed and the final number, if you need longer
'numbers then go ahead and change it.
Global Number1(1 To MaxLen) As Integer
Global Number2(1 To MaxLen) As Integer
Global FinalNum(1 To MaxLen) As Integer
'These Globals here just store the numbers. 'Number1' and 'Number2'
'Are the numbers being processed, and 'FinalNum' is output and is
'processed into a string.
Dim X As Long
Dim Y As Long
'X is a number used for a loop when manipulating the numbers
Dim tempstr As String
Dim tempstrB As String
Dim tempstrC As String
'These are just strings to hold the numbers temporaraly
Dim tempint As Long
Dim tempintB As Long
Dim GotInt As Boolean
Dim Negative As Boolean
'The boolean 'GotInt' is used in the 'PutTogether' function
'so that we don't end up with allot of 0's infrount of the number
'and the boolean 'Neagtive' tells us if we have a negative number or
'not.
Dim LenDec1 As Long
Dim LenDec2 As Long
'These two 'longs' are for storing the position of the decimal place.
'We do this because we remove the decimal place so it's easier to process.
Dim PutInPos As Integer
Public Sub SplitNums(IntA As String, IntB As String)
'This sub splits the stings, AKA the two numbers being procesed,
'into an array where only one number is stored.
LenDec1 = InStr(1, IntA, ".")
If Not LenDec1 = 0 Then
LenDec1 = Len(IntA) - LenDec1
IntA = Replace(IntA, ".", "")
End If
LenDec2 = InStr(1, IntB, ".")
If Not LenDec2 = 0 Then
LenDec2 = Len(IntB) - LenDec2
IntB = Replace(IntB, ".", "")
End If
If Not LenDec1 = LenDec2 Then
If LenDec1 < LenDec2 Then
For X = 1 To LenDec2 - LenDec1
IntA = IntA & "0"
DoEvents
Next
Else
For X = 1 To LenDec1 - LenDec2
IntB = IntB & "0"
DoEvents
Next
End If
End If
If MaxLen <= Len(IntA) Or Len(IntB) Then
'This checks if the max length is longer then either
'of the numbers. If it is then it continues on, if not
'then nothing happens.
For X = 1 To Len(IntA)
'This is a loop of sorts that splits up the first number and
'puts it into an array
Number1(X) = Mid(IntA, Len(IntA) - X + 1, 1)
DoEvents
Next
For X = 1 To Len(IntB)
'This is a loop that splits up the second number and
'puts it into an array
Number2(X) = Mid(IntB, Len(IntB) - X + 1, 1)
DoEvents
Next
End If
End Sub
Public Sub ResetVars()
'This sub resets the values that each function uses. This
'is realy only used because if you don't then it's posiable
'to mix results from previous calculations.
Negative = False
GotInt = False
For X = 1 To MaxLen
Number1(X) = 0
Number2(X) = 0
FinalNum(X) = 0
Next
End Sub
Public Function PutTogether(MathType As Integer) As String
'This function puts the numbers together, in the proper order
'as you may have noticed when the numbers are stored they are
'stored from right to left and not the other way around, this
'is because not every number has the same length, and it's much
'easier to 'line up' the numbers.
tempstr = ""
'We make tempstr = "" because if we don't the we could get a mix
'of results. Eg, the last answer was "232" and this one is "643",
'if we didn't clear this string then it would be "232643"
DoEvents
If MathType = 1 Then
'Addition
If LenDec1 > LenDec2 Then
PutInPos = LenDec1
Else
PutInPos = LenDec2
End If
ElseIf MathType = 2 Then
'Subtraction
If LenDec1 > LenDec2 Then
PutInPos = LenDec1
Else
PutInPos = LenDec2
End If
ElseIf MathType = 3 Then
'Multiplication
PutInPos = LenDec1 + LenDec2
ElseIf MathType = 4 Then
'Division
End If
DoEvents
For X = MaxLen To 1 Step -1
If X = Int(PutInPos) Then
tempstr = tempstr & "."
End If
DoEvents
If FinalNum(X) = 0 And GotInt = False Then
'This if statement checks if the curent number is zero and if
'we already have a number. If we don't have anything then we don't
'bother to add the zero because it is useless info.
Else
GotInt = True
tempstr = tempstr & FinalNum(X)
'This part her just adds the numbers
End If
Next
PutTogether = tempstr
'Once this loop is done we let the function know what the result is.
End Function
Public Function AddNum(Base As String, AddAmount As String) As String
'This Function is self explainitary in what it does, but I'll still explain.
'It adds numbers together.
ResetVars
'We reset the varaiables or else we could get mixed results.
DoEvents
If Left(Base, 1) = "-" And Left(AddAmount, 1) = "-" Then
'This if statement checks if we have negetive numbers. If both
'are negative we remove the minus signs and set the boolean
' 'negative' to true so when we get to the end we get a minus
'at the start of the number. If only one is a negitive number then we
'start the subtraction function and set the result of that as the result
'of this.
Negative = True
Base = Right(Base, Len(Base) - 1)
AddAmount = Right(AddAmount, Len(AddAmount) - 1)
ElseIf Left(Base, 1) = "-" Then
tempstrB = SubNum(AddAmount, Right(Base, Len(Base) - 1))
AddNum = tempstrB
Exit Function
ElseIf Left(AddAmount, 1) = "-" Then
tempstrB = SubNum(Base, Right(AddAmount, Len(AddAmount) - 1))
AddNum = tempstrB
Exit Function
End If
SplitNums Base, AddAmount
'This splits the numbers so we can manipulate them easily
If Len(Base) > Len(AddAmount) Then
tempint = Len(Base)
Else
tempint = Len(AddAmount)
End If
'This if statement finds out how may times we have to loop
For X = 1 To tempint
FinalNum(X) = Int(Number1(X)) + Int(Number2(X)) + Int(FinalNum(X))
'We add the numbers together and then we check wether it's larger or
'or equal to the number 10. If it is we subtract 10 and add 1 to the next
'number
If FinalNum(X) >= 10 Then
FinalNum(X) = Int(FinalNum(X)) - 10
FinalNum(X + 1) = 1
End If
Next
AddNum = PutTogether(1)
'This puts the individual numbers together again in the right order
If Negative = True Then
AddNum = "-" & AddNum
End If
'If this number was a negitive number then we add the minus sign infrount
'of it
If AddNum = "" Then AddNum = 0
'If the number is blank for some strange reason it is then changed to 0
End Function
Public Function SubNum(Base As String, SubAmount As String) As String
'This function is also self explanitory but it basicaly subtracts numbers.
ResetVars
'This sub restarts the variables so errors are less likely
DoEvents
If Left(Base, 1) = "-" And Left(SubAmount, 1) = "-" Then
'This if statement checks if both numbers are negative, if so
'it gets rid of their minus signs and switches them around.
'If there is only one minus sign then it adds the numbers together
'and depending on which one is negative it adds a negitive sign to the
'result.
tempstrC = Right(Base, Len(Base) - 1)
Base = Right(SubAmount, Len(SubAmount) - 1)
SubAmount = tempstrC
ElseIf Left(Base, 1) = "-" Then
tempstrC = AddNum(Right(Base, Len(Base) - 1), SubAmount)
SubNum = "-" & tempstrC
Exit Function
ElseIf Left(SubAmount, 1) = "-" Then
tempstrC = AddNum(Right(SubAmount, Len(SubAmount) - 1), Base)
SubNum = tempstrC
Exit Function
End If
If Base > SubAmount Then
'This if statement decides on which number is larger and splits the numbers
'acordingley.
SplitNums Base, SubAmount
Else
Negative = True
SplitNums SubAmount, Base
End If
If Len(Base) > Len(SubAmount) Then
'This if statement finds out how many times it should loop.
tempint = Len(Base)
Else
tempint = Len(SubAmount)
End If
For X = 1 To tempint
FinalNum(X) = Int(Number1(X)) - Int(Number2(X)) + Int(FinalNum(X))
'This subtracts the numbers
If FinalNum(X) < 0 Then
'This if Statement checks if the number is less then zero and if it is
'then it adds 10 to the curent number and sets the next number to -1
FinalNum(X) = Int(FinalNum(X)) + 10
FinalNum(X + 1) = -1
End If
Next
SubNum = PutTogether(2)
If Negative = True Then
SubNum = "-" & SubNum
End If
'This checks if a negative sign is needed then if it is it adds it.
If SubNum = "" Then SubNum = 0
'If we didn't get a result then we set it to zero. This can occur if
'we are subtracting the same two numbers.
End Function
Public Function MultiplyNum(Base As String, MultiNum As String)
ResetVars
'This resets the variables
DoEvents
If Left(Base, 1) = "-" And Left(MultiNum, 1) = "-" Then
'This if statement decides wether or not the result will be
'negative or not and ajusts the values acordingly
Base = Right(Base, Len(Base) - 1)
MultiNum = Right(MultiNum, Len(MultiNum) - 1)
ElseIf Left(MultiNum, 1) = "-" Then
Negative = True
MultiNum = Right(MultiNum, Len(MultiNum) - 1)
ElseIf Left(Base, 1) = "-" Then
Negative = True
Base = Right(Base, Len(Base) - 1)
End If
SplitNums Base, MultiNum
'This splits the numbers so they can be processed
tempint = Len(Base)
tempintB = Len(MultiNum)
'As you may have noticed we are using two variables to process
'this time. The reason for this is because doing this is like
'doing long multiplacation, therefore making the program
'work faster then if we tried to do it any other way.
For X = 1 To tempint
For Y = 1 To tempintB
FinalNum(X + Y - 1) = FinalNum(X + Y - 1) + (Number1(X) * Number2(Y))
Next
Next
'This is basicaly doing the math here, and making sure we
'don't loose any data, it is posiable for us to get and overflow
'error here. However it's highly unlikely this will happen, however if
'it does occur too often then you can change the dim from an 'integer' to
'a 'long'
For X = 1 To MaxLen
If FinalNum(X) > 10 Then
FinalNum(X + 1) = Int(Left(FinalNum(X), Len(FinalNum(X)) - 1)) + Int(FinalNum(X + 1))
FinalNum(X) = Right(FinalNum(X), 1)
End If
Next
'This sub proceseses the numbers so that we don't have more then one
'character for each value
DoEvents
MultiplyNum = PutTogether(3)
If Negative = True Then
MultiplyNum = "-" & MultiplyNum
End If
'This just adds the negative to the start of the number, that is if
'it is a negative number
If MultiplyNum = "" Then MultiplyNum = 0
End Function
Public Function DivideNum(Base As String, DivByNum As String)
ResetVars
'This clears the variables...
DoEvents
LenDec1 = InStr(1, Base, ".")
If Not LenDec1 = 0 Then
LenDec1 = Len(Base) - LenDec1
Base = Replace(Base, ".", "")
End If
LenDec2 = InStr(1, DivByNum, ".")
If Not LenDec2 = 0 Then
LenDec2 = Len(DivByNum) - LenDec2
DivByNum = Replace(DivByNum, ".", "")
End If
If Not LenDec1 = LenDec2 Then
If LenDec1 < LenDec2 Then
For X = 1 To LenDec2 - LenDec1
Base = Base & "0"
DoEvents
Next
Else
For X = 1 To LenDec1 - LenDec2
DivByNum = DivByNum & "0"
DoEvents
Next
End If
End If
If Left(Base, 1) = "-" And Left(DivByNum, 1) = "-" Then
'This if statement figures wether or not the result
'will be negative.
Base = Right(Base, Len(Base) - 1)
DivByNum = Right(DivByNum, Len(DivByNum) - 1)
ElseIf Left(DivByNum, 1) = "-" Then
Negative = True
DivByNum = Right(DivByNum, Len(DivByNum) - 1)
ElseIf Left(Base, 1) = "-" Then
Negative = True
Base = Right(Base, Len(Base) - 1)
End If
tempint = Len(Base)
tempstrC = Base
'I don't know exactly why I decide to put the
'base into a new string but it seamed to make
'things so much easier
For X = tempint - Len(DivByNum) + 1 To 1 Step -1
'This loop basicaly gets the string or whatever
'it is and manipulates it
DoEvents
If Int(Left(tempstrC, Len(DivByNum) + tempintB)) > Int(DivByNum) Then
Do Until Int(Left(tempstrC, Len(DivByNum) + tempintB)) < (Int(DivByNum) * (10 ^ (X - 1)))
FinalNum(X) = FinalNum(X) + 1
tempstrC = Int(tempstrC) - (Int(DivByNum) * (10 ^ (X - 1)))
Loop
End If
tempintB = tempintB + 1
Next
DivideNum = PutTogether(4)
If Negative = True Then
DivideNum = "-" & DivideNum
End If
If Not tempstrC = "0" Then
If LenDec1 > LenDec2 Then
PutInPos = LenDec1 - LenDec2
Else
PutInPos = LenDec2 - LenDec1
End If
DivideNum = DivideNum & " - Remainder " & (Int(tempstrC) / (10 ^ PutInPos))
End If
'These parts just add the nesacary parts and also it gives the remainder.
End Function
[Ovu poruku je menjao krckoorascic dana 11.08.2006. u 03:23 GMT+1]
Seeking