Hi everyone,
I have a tiny problem here but just cant handle it, since I'm new to VB6..
I want to put a code into a module which contains a lot of lines with same objects. I have an idea of relating those objects with variables, so instead of, for example, form1.picture1.backcolor = form1.picture2.backcolor the code line would look like A = B or something, but I just cant find a right way to do it. To make it clear, I need to relate form1.picture1.backcolor with variable A, form1.picture2.backcolor with B etc., and be able to use those in a module. So any ideas would really make it easier..

Hi, To relate code and object, class module can be useful. Inside a class module have a reference of Form or Picture box.

'In class Module
Dim A as Form1
'or
Dim A as PictureBox

so you can use
'If it is Form
A.Picture1.BackColor = vbRed
'If it is a picture box
A.BackColor = vbBlack

But the object A must refer the Form or PictureBox before using its properties and Methods.

Thanks salva, that's something what I've already tried to use. But is it possible to relate the whole path with the variable? Let's say Dim A as form1.pic1.backcolor or something? Maybe I should involve Set statement? I'm quite lost..

It is possible to refer whole path (Form1.Pic1.BackColor) only when that the whole path refers an Object.

But BackColor is Long data type also it is not a reference type. You cannot refer this. Why i am saying reference type is when you change anything in reference type it also reflect on all the reference that refers the same object.

The primitive types long, int, ... these are value type. and classes (Controls, Form, User defined class modules) are reference type.

This article has been dead for over six months. Start a new discussion instead.