Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass an array of reals to a 3d party dll
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01091099
Message ID:
01091258
Views:
16
I tried BINTOC, actually I used the following code to convert to a double char and integer to char representation and defined both double and integer arrays as strings as you recommended but with no success, I get the message "Data type mismatch". In case you would like to have a more thorough look I also attach how the function is beeing called from a C program (see the function : add_constraintex ( in case you want to know whats all this about , this is a free linear programming api, see http://lpsolve.sourceforge.net/5.5/ and I try to use it to do routing optimization)).

Thanks
FUNCTION DOUBLEARRAYTOCHAR
*****************************
LPARAMETERS lanArray
LOCAL lcChar
lcChar = ""

FOR ii=1 TO ALEN(lanArray)
  lcChar = lcChar + BINTOC(lanArray(ii), "BR")
ENDFOR 

RETURN lcChar

ENDFUNC 


FUNCTION INTARRAYTOCHAR
*****************************
LPARAMETERS lanArray
LOCAL lcChar
lcChar = ""

FOR ii=1 TO ALEN(lanArray)
  lcChar = lcChar + BINTOC(lanArray(ii), "R")
ENDFOR 

RETURN lcChar

ENDFUNC 
Here is the C code :
#include "lp_lib.h"

int demo()
{
  lprec *lp;
  int Ncol, *colno = NULL, j, ret = 0;
  REAL *row = NULL;

  /* We will build the model row by row
     So we start with creating a model with 0 rows and 2 columns */
  Ncol = 2; /* there are two variables in the model */
  lp = make_lp(0, Ncol);
  if(lp == NULL)
    ret = 1; /* couldn't construct a new model... */

  if(ret == 0) {
    /* let us name our variables. Not required, but can be useful for debugging */
    set_col_name(lp, 1, "x");
    set_col_name(lp, 2, "y");

    /* create space large enough for one row */
    colno = (int *) malloc(Ncol * sizeof(*colno));
    row = (REAL *) malloc(Ncol * sizeof(*row));
    if((colno == NULL) || (row == NULL))
      ret = 2;
  }

  if(ret == 0) {
    set_add_rowmode(lp, TRUE);  /* makes building the model faster if it is done rows by row */

    /* construct first row (120 x + 210 y <= 15000) */
    j = 0;

    colno[j] = 1; /* first column */
    row[j++] = 120;

    colno[j] = 2; /* second column */
    row[j++] = 210;

    /* add the row to lpsolve */
    if(!add_constraintex(lp, j, row, colno, LE, 15000))
      ret = 3;
  }

  if(ret == 0) {
    /* construct second row (110 x + 30 y <= 4000) */
    j = 0;

    colno[j] = 1; /* first column */
    row[j++] = 110;

    colno[j] = 2; /* second column */
    row[j++] = 30;

    /* add the row to lpsolve */
    if(!add_constraintex(lp, j, row, colno, LE, 4000))
      ret = 3;
  }

  if(ret == 0) {
    /* construct third row (x + y <= 75) */
    j = 0;

    colno[j] = 1; /* first column */
    row[j++] = 1;

    colno[j] = 2; /* second column */
    row[j++] = 1;

    /* add the row to lpsolve */
    if(!add_constraintex(lp, j, row, colno, LE, 75))
      ret = 3;
  }

  if(ret == 0) {
    set_add_rowmode(lp, FALSE); /* rowmode should be turned off again when done building the model */

    /* set the objective function (143 x + 60 y) */
    j = 0;

    colno[j] = 1; /* first column */
    row[j++] = 143;

    colno[j] = 2; /* second column */
    row[j++] = 60;

    /* set the objective in lpsolve */
    if(!set_obj_fnex(lp, j, row, colno))
      ret = 4;
  }

  if(ret == 0) {
    /* set the object direction to maximize */
    set_maxim(lp);

    /* just out of curioucity, now show the model in lp format on screen */
    /* this only works if this is a console application. If not, use write_lp and a filename */
    write_LP(lp, stdout);
    /* write_lp(lp, "model.lp"); */

    /* I only want to see important messages on screen while solving */
    set_verbose(lp, IMPORTANT);

    /* Now let lpsolve calculate a solution */
    ret = solve(lp);
    if(ret == OPTIMAL)
      ret = 0;
    else
      ret = 5;
  }

  if(ret == 0) {
    /* a solution is calculated, now lets get some results */

    /* objective value */
    printf("Objective value: %f\n", get_objective(lp));

    /* variable values */
    get_variables(lp, row);
    for(j = 0; j < Ncol; j++)
      printf("%s: %f\n", get_col_name(lp, j + 1), row[j]);

    /* we are done now */
  }

  /* free allocated memory */
  if(row != NULL)
    free(row);
  if(colno != NULL)
    free(colno);

  if(lp != NULL) {
    /* clean up such that all used memory by lpsolve is freed */
    delete_lp(lp);
  }

  return(ret);
}

int main()
{
  demo();
}
>In VFP9 use BINTOC() to convert FoxPro numeric values to binary character representation.
>
>Convert each numeric to DOUBLE binary character representation and assemble them in a string buffer. In the declaration statement instead of
>...DOUBLE row...
>use
>...STRING @row...
>and pass this string buffer as row parameter.
>
>It may work.
Previous
Reply
Map
View

Click here to load this message in the networking platform