Example Passing Numeric Variables from Basic to C by Value (27291)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q27291

SUMMARY

The program below demonstrates how to pass numeric values from compiled Basic to Microsoft C by VALUE.

MORE INFORMATION

For more information about passing other types of parameters between Basic and C, and a list of which Basic and C versions are compatible with each other, query in the Microsoft Knowledge Base using the following word:

BAS2C

Code Example

REM ===== Basic PROGRAM =====

DECLARE SUB NumericValue CDECL (_
            BYVAL p1 AS INTEGER,_
            BYVAL p2 AS LONG,_
            BYVAL p3 AS SINGLE,_
            BYVAL p4 AS DOUBLE)
a% = 32767
b& = 32769
c! = 123.312
d# = 129381.333#
CLS
CALL NumericValue(a%, b&, c!, d#)
END

/* ===== C ROUTINE ===== */ 
/* The variables are put into structs for memory alignment. */ 
#include <stdio.h>
struct struct_int{
   int x;
   };
struct struct_long{
   long x;
   };
struct struct_float{
   float x;
   };
struct struct_double{
   double x;
   };
void NumericValue(a, b, c, d)
   struct struct_int a;
   struct struct_long b;
   struct struct_float c;
   struct struct_double d;
   {
         printf("INTEGER  %d        \n",a.x);
         printf("LONG     %ld        \n",b.x);
         printf("FLOAT    %f        \n",c.x);
         printf("DOUBLE   %lf        \n",d.x);
   }
				
===== OUTPUT =====

INTEGER  32767
LONG     32769
FLOAT    123.311996
DOUBLE   129381.333000
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB27291