VB6 Require some help with looping
I am trying to convert a source from C++ to vb6:
C++:
static double mdArray[3][3];
static double mdArray2[3][3];
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
double sum = 0;
for(k = 0; k < 3; k++)
sum = sum + mdArray[k]开发者_开发技巧[i] * mdArray[k][k];
mdArray2[i][j] = sum
}
VB6:
dim mdArray(0 to 2, 0 to 2) as integer
dim mdArray2(0 to 2, 0 to 2) as integer
for i = 0 to 2
for j = 0 to 2
dim a as double
sum = 0
for k = 0 to 2
sum = sum + mdArray(k,i) * mdArray(k,j)
mdArray2(i,j) = sum
Next
Next
Next
Will the vb6 version yield the same result as the C++ version? Thanks.
Did you even bother to try it? Here's the errors I could spot:
- You declare your arrays with the wrong datatype
- You're declaring
a
instead ofsum
for some reason - You have
mdArray(k, j)
instead ofmdArray(k, k)
- Your innermost
Next
statement should be beforemdArray2(i,j) = sum
, not after it.
Will the vb6 version yield the same result as the C++ version?
Did you try it?
Your arrays are declared as double
in C++ but Integer
in VB6. Apart from that, the codes look pretty identical, except for the innermost loop (using proper indentation would have prevented this mistake easily!):
for k = 0 to 2
sum = sum + mdArray(k,i) * mdArray(k,j)
Next
mdArray2(i,j) = sum
The dArray2(i,j) = sum
line belongs outside the loop.
精彩评论