User Control VB6 ... QUICK HELP NEEDED!!!

Started by
1 comment, last by estherkertz 18 years, 8 months ago
Hello... im buildign a user control in VB6. its acutally an icon with diff functions. through a click event on the icon a dialog is opened... my project for the uc consists of a form for the dialog and the actual UC. i would like to access the .Name property of the UC from the codewindow of the dialog. in order to use the .Name of the UC as part of the .Caption of the dialog that pops up... lets say ucPump.Name --> Pump1 in the load form part of the dialog: --> dialog.Caption = "Name of Pumpe" &ucPump.Name ... something like this. im new to VB6 and the tutorials i did didnt provide any info on things like this... so id need some help... THANK YOU
Advertisement
This should basically do what you want. It's been a long time since I've done UserControls in VB6, so there's probably a better solution out there someplace, but this ought to do for starters.

' In the dialog formDim MyControlReference As TheControlPublic Sub SetControl(ByRef ControlReference As TheControl)  MyControlReference = TheControl  Debug.Print MyControlReference.NameEnd Sub' In the UserControlPrivate Sub TheControl_Click()  Dim dialog As TheDialog  dialog = New TheDialog  dialog.SetControl Me.Object  dialog.Show vbModal  dialog = NothingEnd Sub



Basically, the dialog needs to be told what control to "attach" itself to. Once it knows this, it can access it and manipulate it as a normal control. To accomplish this, we simply add a step when we create the dialog, and tell it what control to attach to via our new custom SetControl routine.

Note that SetControl is passed "Me.Object" from the UserControl rather than just Me. This is to ensure that the value given to SetControl is of type TheControl, in case the UserControl is given a default property.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

It seems to me as if my problem was understood like:

i got a project... import a working user control and add a dialog-form.
then make them work together...


but im still working on the user control...
and withing my usercontrol-project i got code for the usercontrol part and code for the dialog....
and i want to those to work together... the problem is that i cannot call the ucPump in the code window of the dialog... cause withing the project the usercontrol might not be known yet by ucPump...
maybe...
im not sure. thats an assumption...

How can i make them work together?????

This topic is closed to new replies.

Advertisement