开发者

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.


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.


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


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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜