Convert C++ to VBA

jamhurijamal

New Member
Joined
May 5, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hye,

I'm having trouble converting the C++ coding.
Could anyone please help me in converting the C++ to VBA?

Thank you.

// Definition of Fitness Functions
double func(double x[][pop], int i)
{
NumOfEvalCounter++;

double y ;

y = x[0] * (pow(x[1], 4) - 0.8*pow(x[2], 4) - 0.0000000263396);
//y = -y;

return y;
}


double randfunc(double xs, double xe) // Definition of Random number Generator Function
{
double randnum;

randnum = rand();
randnum = xs + randnum*(xe - xs) / RAND_MAX;

return randnum;
}

double myrandom()
{
double r;
int M, x;

M = 10000;
x = M - 2;
r = (1.0 + (rand() % x)) / M;

return r;
}

void funcSort(double inP1[], double oP1[], double inP2[][pop], double oP2[][pop], int size)
{
// double temp1=inP1[0];
int temp2;
double temp1 = -INT_MAX;

for (int j = 0; j<size; j++) //sort
{
for (int k = 0; k<size; k++)
if (inP1[k]> temp1)
{
temp1 = inP1[k];
temp2 = k;
}

oP1[j] = temp1;

for (int d = 0; d<dim; d++)
oP2[d][j] = inP2[d][temp2];


temp1 = -INT_MAX;

inP1[temp2] = -INT_MAX;

} //end sort
}
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Which part are you having trouble with?
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top