Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a variable in VB6?

Tags:

vb6

Is it possible in Visual Basic 6 to make some variable to reference to another variable, so when one changes, so does the other?

I know it is possible to use Set operator for objects. But how to make this work for integer type variables? The only way I am aware of is to wrap the variable inside an object.

like image 403
ezpresso Avatar asked Sep 09 '26 21:09

ezpresso


1 Answers

Not through the language itself. You could use a class as you mentioned, the other way is to use the Win32 API.

Specifically

HeapAlloc to allocate memory. You will store the returned address in a Long variable.

Then use RTLMoveMemory renamed as CopyMemory to transfer data in and out of the allocated memory.

Public Declare Sub CopyMemory Lib "kernel32" Alias _
    "RtlMoveMemory" (Destination As Any, Source As Any, _
    ByVal Length As Long)

This website has a more complete example of using pointers in VB6.

like image 121
RS Conley Avatar answered Sep 16 '26 22:09

RS Conley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!