tags:

views:

65

answers:

2

Hi, 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.

+3  A: 

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.

Konrad Rudolph
+5  A: 

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.
Matti Virkkunen
+1 And it's easy to try it. Visual C++ express edition is free. Presumably you have VB6 (otherwise there's not much point in the exercise)
MarkJ