Referring form objects in VB 2005.

S

Sugan

Hi all,

I'm converting a VB 6 exe project to a VB 2005 project.

One main functionality in VB 6 that gives errors in VB 2005 project is
as follows:

In VB6, i have a initial form called frmApplication that loads up.
There are two other forms Form1 and Form2. Based on the user settings,
frmApplication then loads either Form1 or Form2. Form1 and Form2
differs only by appearance. What i mean, all the controls in both the
forms are same including the name except there position of the control
on the respective forms.

When frmApplication is loaded, it creates a object of Form1 or Form2
depends on the setting and assigns to frmObject.

Now in VB6, i access the controls in Form1 or Form2 in runtime using

frmObject.lblName.Caption = "Somename"

While in VB 2005, i'm not able to refer the controls in the similar
manner. How is it possible to get the same functionality in VB 2005.

Thanks,
Sugan.
 
P

Patrice

Select this control (and all other appropriate controls) and set its "
Modifiers" property to whatever best fit (such as "friend"). Controls in VB
2005 are "private" by default.
Another option would be to expose this as a property instead of exposing the
control directly.

Also what is the type of frmObject ? It will work if you are using late
binding but if you want to use strong typing you'll have to use a type that
is compatible with both forms...

Another option could be to move the controls by code (as it seems the only
difference is their position).
 
S

Sugan

Hi,

Thanks for your reply. As you said in your second para, i'm using late
binding.

Here is my VB 6 code.

Code:

Dim frmObject as form

Private Sub Form_Load() 'frmApplication_load

If UserSetting = 1 then ' Check the appearnce required by user
frmObject = New Form1
Else
frmObject = New Form2
End if

'Both the forms have the same controls ( their name is even same)
except for 'their positions in the corresponding form. So now i access
as

frmObject.lblName.Caption = "Somename"

'I need how about to do this as frmObject is not visible in My.Forms

End sub

Thanks,
Sugan
 

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