开发者

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:

  1. You declare your arrays with the wrong datatype
  2. You're declaring a instead of sum for some reason
  3. You have mdArray(k, j) instead of mdArray(k, k)
  4. Your innermost Next statement should be before mdArray2(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜