How can pointers be used in VB?

M

Michael

Hello,

How can pointers be used in VB?
Here is an example in 'C'
How can the same be done in VB?

(I am using MS Access 2000)

Thanks,

Michael


Code: -------------------------------------


typedef far struct point {
float x;
float y;
float z;
float d;
struct point far *nextX;
struct point far *nextY;
} far Point;


void main(void)
{
float a,b,c;
Point far *p2D;

/*... code ...*/

CalculPts(a,b,c,&p2D);

} /* main */



void CalculPts(float aa, float bb, float cc, Point far
**pt2D)
{
Point far *currentX,far *currentY;


*pt2D = (Point far *) farmalloc(sizeof(Point));
currentX = *pt2D;
currentY = *pt2D;

currentX->x = aa;
currentX->y = bb;
currentX->z = cc;
currentX->d = 1;

/*... code ...*/

currentX->nextX=NULL;
currentX->nextY = currentY;

/*... code ...*/

if (currentX->nextX!=NULL) currentX = currentX->nextX;

/*... code ...*/

currentY->nextY = (Point far *) farmalloc(sizeof
(Point));
if (currentY!=NULL) currentY = currentY->nextY;

} /* CalculPts */
 
A

Albert D. Kallal

No, VB does not have pointers. You can pass vars to a function or sub as "by
ref" as opposed to "by value"

So, using by "ref" means that only a pointer to the variable in memory is
passed. This of course is faster, as a "copy" of the value is not made.

Any values passed to the sub/function, and then changed in that sub/function
will thus be returned/changed to the calling routine.

However, returning a values is certainly not a "pointer" data type, and thus
making a "linked" list as you have is not very easy in VB.

To create a dynamic structure in VB that has "N" values, likely a collection
is a good deal better then resorting to a array. The only draw back of a
collection is that each element of the collection can't be modified in the
collection (you would have to remove it first).
 
T

Tim Ferguson

However, returning a values is certainly not a "pointer" data type,
and thus making a "linked" list as you have is not very easy in VB.

Ooh me, ooh me, me, please teacher!

I wrote one of these ages ago, when I was still full of all that data
structures stuff they taught us in uni. IIRC, I used an array of user types
that included an integer to point to the index of the "next" array member.
Come to think of it, I think I did a dequeue too!

Then, of course, we all grew up and just used Collection objects because
that is what they are for!

All the best


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top