Home > Software engineering >  VB array strange problems in calculation
VB array strange problems in calculation

Time:10-05

To compile a more than a calculated by two Numbers used for the calculation of going to account more large Numbers of digits, but in the process of the test run a very strange question: input array, two can correct the results, but 121 divided by 11122 1 divided by the number of these, including 11, but prompt "index array limit is... ! "" Saw a few times also can not find where is fritz, freaked out, recognize advice please! The HTML code is as follows, is a little long, please patience guidance, error figure also attach,
The Do While m=0

If UBound (a) & lt; Then UBound (b)
R=1
The Exit Do
End the If
'if (a) digit less than the median of b (a), the tags have remainder, jump out the do loop
For z=UBound (b) Step 1 To 0
If a (UBound (a), UBound (b) + z) & gt; B (z) Then
Y=UBound (a), UBound (b)
Mm=1
The Exit For
'judging from high to low, if there is a () is greater than b (), you can subtract and determine the position of the beginning subtraction, jump out of the for loop
ElseIf a (UBound (a) to UBound (b) + z) & lt; B (z) And UBound=UBound (a) (b) Then
R=1
The Exit Do
'if emerged from high () is less than b (), and a () and b () digits are equal, is not enough, tag has the remainder, jump out the do loop
ElseIf a (UBound (a) to UBound (b) + z) & lt; B (z) And UBound (a) & gt; Then UBound (b)
Y=UBound (a), UBound (b) - 1
Mm=1
The Exit For
'if (a) digits enough, then start by subtracting the position of the back down a
End the If
Next
If the mm=0 And UBound (a) & gt; Then UBound (b)
ReDim Preserve a (UBound (a) to UBound (b) - 1)
'if compare the Numbers are equal, all digits, it decreases after the admiral is 0, so directly to these digital removed
ElseIf mm=0 And UBound=UBound (a) (b) Then
R=0
The Exit Do
'if all the Numbers on the digits are equal and a () and b () digits are equal, equal, two number tags directly without remainder, jump out the do loop
End the If
If=1 mm Then
For z=0 To UBound (b)
If a (y + z) & lt; B (z) Then
A (y + z)=a (y + z) + 10
A (y + z + 1)=a (y + z + 1) - 1
End the If
'when can subtract, not enough to reduce the location for a borrow
A (y + z)=a (y + z) - b (z)
Next
End the If

For z=UBound (a) To 1 Step - 1
If a (z)=0 Then
ReDim Preserve a (UBound (a) - 1)
The Else
The Exit For
End the If
Next
'after subtracting, equal to zero is invalid number will be high to remove
If UBound (a)=0 And a (0)=0 Then
R=0
The Exit Do
End the If
'if you go to the last one or zero, the tag has no remainder
Loop

TextBox1. Text=TextBox1. Text & amp; VbCrLf & amp; R

CodePudding user response:

You confirm a (y + z) the index does not exceed a?

CodePudding user response:

Didn't understand your "array" is how come of,
The original poster had better stick the code complete,
What don't you this kind of code, but also involves the "secret"!

In addition, VB6 have residual operation,
Why want to get this algorithm upside down?
Even write my own, why use "array"?

CodePudding user response:

The original poster is the study of the what? The custom "mod" function?

CodePudding user response:

Custom mod function, want to use in some of large number of processing, such as more than 20, with VB is not built-in functions, the array is made of two input box input, does not involve what secret, just feel part of the input box content between the two array is a little long, but it doesn't matter with this problem, so I didn't stick, the y=ubound (a) to ubound (b), z from 0 to ubound (b) oh, y + z is smallest ubound (a) - ubound (b), is the largest ubound (a) oh, how could be more than an array boundaries? And several other can calculate, 121 divided by 11122 1 divided by 11 class number that's not, who is going to answer me!

CodePudding user response:

You have a look at the index in error values are not clear? Big step walk again,

CodePudding user response:

 y=UBound (a) - UBound (b) '& lt; - first y 
.
ReDim Preserve a (UBound (a) - 1) '& lt; - the array has a smaller!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.
For z=0 To UBound (b)
If a (y + z) & lt; B (z) Then
  • Related