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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Which part are you having trouble with?
 
Upvote 0

Forum statistics

Threads
1,215,590
Messages
6,125,698
Members
449,250
Latest member
azur3

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