ezpresso
ezpresso

Reputation: 8136

How to reference a variable in 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.

Upvotes: 3

Views: 2145

Answers (4)

vbguyny
vbguyny

Reputation: 1172

I wrote a custom Reference Object class which sounds like it would do exactly what you are looking for. You can read up on it and download it here: http://battaglia.homedns.org/vbguyny/development/visualbasic6/visualbasic6_20070218.htm

Upvotes: 1

Jeff
Jeff

Reputation: 141

The method of assigning a variable to a text box to set a reference is wrong. It does not do what is stated. Assigning a variable to a text box or assigning a text box to a variable COPIES the content of the text box to the variable. It is not setting a reference to it!

Upvotes: 0

rekcah101
rekcah101

Reputation: 27

try putting variable A in a textbox then make an on change event on the text box., then put the value the text to variable B.

textbox1.text = A

onchgange textbox1 B= textbox1.text

its wat im using., the most easiest way for me

Upvotes: 0

RS Conley
RS Conley

Reputation: 7196

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.

Upvotes: 2

Related Questions