Home All Groups Group Topic Archive Search About

How to make this call from form to control

Author
16 Mar 2009 2:12 PM
Faraz Azhar
Hello

I'm making a control project. This usercontrol connects to internet
and downloads some infos. So it shows a plain form showing the
progress of downloads.

The form doesn't have any code inside. The progress bar on the form is
controlled by the WinSock inside my usercontrol.

Now I want to put a Cancel button on the form. This cancel button
should call a sub (called CancelOperation) in the usercontrol, which
will disconnect the WinSock and unload the Form.

Problem is: How do I call a subroutine from a Form to a usercontrol?
If it was a different form/module, I would write
Form2.CancelOperation. But since the usercontrol is not a class, Im
confused on how to call a sub from the usercontrol.

Secondly, even if there was some way of calling the sub... I'll have
to make that sub as Public (I think). Now this will reveal my
CancelOperation sub to the users of the control. I don't want that to
happen.

So how should I handle this coding situation?

Author
16 Mar 2009 2:27 PM
Larry Serflaten
"Faraz Azhar" <itzfa***@gmail.com> wrote

> The form doesn't have any code inside. The progress bar on the form is
> controlled by the WinSock inside my usercontrol.

Please excuse the obvious, but why isn't the progress bar and
Cancel button on the User Control?

LFS
Author
16 Mar 2009 2:54 PM
Faraz Azhar
On Mar 16, 7:27 pm, "Larry Serflaten" <serfla***@usinternet.com>
wrote:
> "Faraz Azhar" <itzfa***@gmail.com> wrote
>
> > The form doesn't have any code inside. The progress bar on the form is
> > controlled by the WinSock inside my usercontrol.
>
> Please excuse the obvious, but why isn't the progress bar and
> Cancel button on the User Control?
>
> LFS

Because the usercontrol is supposed to be a hidden control. Its
supposed to show various popup windows (dialog forms) asking users
about stuff. Just one popup window shows the progress bar of
downloading content from website.
Author
16 Mar 2009 4:11 PM
mayayana
>
Because the usercontrol is supposed to be a hidden control. Its
supposed to show various popup windows (dialog forms) asking users
about stuff. Just one popup window shows the progress bar of
downloading content from website.
>

   Are you aware that you don't have to compile
your control as an OCX? It actually makes much more
sense not to, when that's feasible. It can be faster
and doesn't need to be registered. Just compile it into
your EXE.
   In your case it sounds like there wouldn't
be any reason to do otherwise, since you want the
control to be hidden and unusable from the outside.
Author
16 Mar 2009 4:59 PM
Faraz Azhar
Show quote Hide quote
On Mar 16, 9:11 pm, "mayayana" <mayayaX***@rcXXn.com> wrote:
> Because the usercontrol is supposed to be a hidden control. Its
> supposed to show various popup windows (dialog forms) asking users
> about stuff. Just one popup window shows the progress bar of
> downloading content from website.
>
>
>
>    Are you aware that you don't have to compile
> your control as an OCX? It actually makes much more
> sense not to, when that's feasible. It can be faster
> and doesn't need to be registered. Just compile it into
> your EXE.
>    In your case it sounds like there wouldn't
> be any reason to do otherwise, since you want the
> control to be hidden and unusable from the outside.

My plan is to make an ActiveX OCX which can be installed once on the
user's system and many applications can use it.

@Dave O.
yes that would be a very tacky way of doing it. I'm wondering how
others do it.. ? My activeX is supposed to be a invisible control. The
applications will call the Connect function and it will show a popup
window that shows a downloading progressbar. Thats it. simple!

What Im asking is that is there a way I can code in the Cancel button
that: usercontrol.CancelOperation  ? but the 'usercontrol' is a
control so it cannot be used this way. Is there any other way of
calling the CancelOperation sub, without revealing it to other
applications?
Author
16 Mar 2009 7:20 PM
Larry Serflaten
"Faraz Azhar" <itzfa***@gmail.com> wrote

> My plan is to make an ActiveX OCX which can be installed once on the
> user's system and many applications can use it.

I was never fond of 'kitchen sink' applications (or controls).  I rather
prefer focused applications that do one job well...  Thus, the idea
that the UC would make the connection and show its progress, etc...

> What Im asking is that is there a way I can code in the Cancel button
> that: usercontrol.CancelOperation  ? but the 'usercontrol' is a
> control so it cannot be used this way.

That's a bit like saying you want to put text in a textbox by using
Text1.Text, but its a control and can't be used that way.

Controls can have properties, functions, and methods.  Why not
add the CancelOperation method, if that is what it needs  ???

If you mean you want to create a control that only your applications
can use, that is also possible.

In that case, create a type library that has the UserControl interface
you want supported, and implement that in the UserControl.  Then
in your UC, add code only to methods of that interface.

With the Type Library on your system (An ActiveX Dll with one
class defining the interface) you can reference it in your projects
but as long as you don't give it out, no one else will even know
it is there.  Your applications talk to your user control through that
interface, just like it was a normal control...

Dim MyUC As IHiddenInterface
Set MyUC = UserControl11.Object
' Now use MyUC to access the UC
MyUC.CancelOperation

But be careful, once you define your hidden interface, and implement
it in your UserControl, tuck it away and don't change anything.  If you
break compatibility by adding something to the interface, you won't be
able to talk to your usercontol. (It will be expecting the old version and
will show type mismatch for anything else.)

LFS
Author
16 Mar 2009 9:11 PM
Faraz Azhar
Show quote Hide quote
On Mar 17, 12:20 am, "Larry Serflaten" <serfla***@usinternet.com>
wrote:
> "Faraz Azhar" <itzfa***@gmail.com> wrote
>
> > My plan is to make an ActiveX OCX which can be installed once on the
> > user's system and many applications can use it.
>
> I was never fond of 'kitchen sink' applications (or controls).  I rather
> prefer focused applications that do one job well...  Thus, the idea
> that the UC would make the connection and show its progress, etc...
>
> > What Im asking is that is there a way I can code in the Cancel button
> > that: usercontrol.CancelOperation  ? but the 'usercontrol' is a
> > control so it cannot be used this way.
>
> That's a bit like saying you want to put text in a textbox by using
> Text1.Text, but its a control and can't be used that way.
>
> Controls can have properties, functions, and methods.  Why not
> add the CancelOperation method, if that is what it needs  ???
>
> If you mean you want to create a control that only your applications
> can use, that is also possible.
>
> In that case, create a type library that has the UserControl interface
> you want supported, and implement that in the UserControl.  Then
> in your UC, add code only to methods of that interface.
>
> With the Type Library on your system (An ActiveX Dll with one
> class defining the interface) you can reference it in your projects
> but as long as you don't give it out, no one else will even know
> it is there.  Your applications talk to your user control through that
> interface, just like it was a normal control...
>
> Dim MyUC As IHiddenInterface
> Set MyUC = UserControl11.Object
> ' Now use MyUC to access the UC
> MyUC.CancelOperation
>
> But be careful, once you define your hidden interface, and implement
> it in your UserControl, tuck it away and don't change anything.  If you
> break compatibility by adding something to the interface, you won't be
> able to talk to your usercontol. (It will be expecting the old version and
> will show type mismatch for anything else.)
>
> LFS

Hmm.. very interesting! I'll look into the possibilities of rewriting
my code or using type libs, whichever turns out to be best.
thanks all for your advises!
Author
16 Mar 2009 2:51 PM
Dave O.
"Faraz Azhar" <itzfa***@gmail.com> wrote in message
news:e8334d95-6cd5-4e02-bf96-8ab1c7eec1ba@o2g2000prl.googlegroups.com...
> Hello

> Secondly, even if there was some way of calling the sub... I'll have
> to make that sub as Public (I think). Now this will reveal my
> CancelOperation sub to the users of the control. I don't want that to
> happen.

Seems odd you'd want to hide such a function, but if you really must the
easiest way and the worst (from a programming perspective) would be to add
it to an existing function but only with very specific parameter(s),
something like:

Public Sub InitDownload(DownURL as string)
If DownURL = "XX_RESET_XX" then
  CancelOperation
Else
' Normal Init code
end if

Truly tacky but it would work and does what you want.
You'll may also need the control to release processor cycles to allow the
button to be pressed, if so just add a DoEvents in the main loop somewhere
ensuring it is hit at least twice a second but no more than about 15 times a
second.

Dave O.
Author
16 Mar 2009 9:04 PM
Eduardo
Could you explain better what you are trying to do?

What I think I understood or misunderstood is:

You are writing an usercontrol to do something.
It is invisible.
You'll ask your usercontrol's users to add a progressbar to the same form
that you will control it from the usercontrol (how?)
Now you also will ask them to add a cancel button, and you want to get the
click event of that cancel button from inside your usercontrol. Is that
right?

How do you bind the progress bar and the cancel button to the usercontrol?


Show quoteHide quote
"Faraz Azhar" <itzfa***@gmail.com> escribió en el mensaje
news:e8334d95-6cd5-4e02-bf96-8ab1c7eec1ba@o2g2000prl.googlegroups.com...
> Hello
>
> I'm making a control project. This usercontrol connects to internet
> and downloads some infos. So it shows a plain form showing the
> progress of downloads.
>
> The form doesn't have any code inside. The progress bar on the form is
> controlled by the WinSock inside my usercontrol.
>
> Now I want to put a Cancel button on the form. This cancel button
> should call a sub (called CancelOperation) in the usercontrol, which
> will disconnect the WinSock and unload the Form.
>
> Problem is: How do I call a subroutine from a Form to a usercontrol?
> If it was a different form/module, I would write
> Form2.CancelOperation. But since the usercontrol is not a class, Im
> confused on how to call a sub from the usercontrol.
>
> Secondly, even if there was some way of calling the sub... I'll have
> to make that sub as Public (I think). Now this will reveal my
> CancelOperation sub to the users of the control. I don't want that to
> happen.
>
> So how should I handle this coding situation?
Author
16 Mar 2009 9:49 PM
Eduardo
I re read and now I think I got it.

The form is yours, it's a form of your ActiveX project.

OK, if you want to add a method that is visible for inside your activex
project but not from the outside, then just define it as "Friend".

' Inside your usercontrol code:

Friend Sub Cancel ()
    'do something to perform the cancel operation
End Sub

'Let's suppose the name of your form is frmShowProgess, then prior to show
it:

set frmShowProgess.pUC = Me

' then show it

frmShowProgess.Show

'In the code of the form:

Public pUC as YourUserControlTypeName

' if the cancel button's name is cmdCancel the code is:

Private Sub cmdCancel_Click()
    pUC.Cancel
End Sub



Show quoteHide quote
"Eduardo" <m*@mm.com> escribió en el mensaje news:gpmeta$41j$1@aioe.org...
> Could you explain better what you are trying to do?
>
> What I think I understood or misunderstood is:
>
> You are writing an usercontrol to do something.
> It is invisible.
> You'll ask your usercontrol's users to add a progressbar to the same form
> that you will control it from the usercontrol (how?)
> Now you also will ask them to add a cancel button, and you want to get the
> click event of that cancel button from inside your usercontrol. Is that
> right?
>
> How do you bind the progress bar and the cancel button to the usercontrol?
>
>
> "Faraz Azhar" <itzfa***@gmail.com> escribió en el mensaje
> news:e8334d95-6cd5-4e02-bf96-8ab1c7eec1ba@o2g2000prl.googlegroups.com...
>> Hello
>>
>> I'm making a control project. This usercontrol connects to internet
>> and downloads some infos. So it shows a plain form showing the
>> progress of downloads.
>>
>> The form doesn't have any code inside. The progress bar on the form is
>> controlled by the WinSock inside my usercontrol.
>>
>> Now I want to put a Cancel button on the form. This cancel button
>> should call a sub (called CancelOperation) in the usercontrol, which
>> will disconnect the WinSock and unload the Form.
>>
>> Problem is: How do I call a subroutine from a Form to a usercontrol?
>> If it was a different form/module, I would write
>> Form2.CancelOperation. But since the usercontrol is not a class, Im
>> confused on how to call a sub from the usercontrol.
>>
>> Secondly, even if there was some way of calling the sub... I'll have
>> to make that sub as Public (I think). Now this will reveal my
>> CancelOperation sub to the users of the control. I don't want that to
>> happen.
>>
>> So how should I handle this coding situation?
>
>
Author
16 Mar 2009 9:52 PM
Eduardo
PS: procedures defined as Friend are public from within the ActiveX project
but not visible from the outside.

Show quoteHide quote
"Eduardo" <m*@mm.com> escribió en el mensaje news:gpmhh9$73t$1@aioe.org...
Author
17 Mar 2009 1:34 AM
Karl E. Peterson
Faraz Azhar wrote:
Show quoteHide quote
> I'm making a control project. This usercontrol connects to internet
> and downloads some infos. So it shows a plain form showing the
> progress of downloads.
>
> The form doesn't have any code inside. The progress bar on the form is
> controlled by the WinSock inside my usercontrol.
>
> Now I want to put a Cancel button on the form. This cancel button
> should call a sub (called CancelOperation) in the usercontrol, which
> will disconnect the WinSock and unload the Form.
>
> Problem is: How do I call a subroutine from a Form to a usercontrol?
> If it was a different form/module, I would write
> Form2.CancelOperation. But since the usercontrol is not a class, Im
> confused on how to call a sub from the usercontrol.
>
> Secondly, even if there was some way of calling the sub... I'll have
> to make that sub as Public (I think). Now this will reveal my
> CancelOperation sub to the users of the control. I don't want that to
> happen.
>
> So how should I handle this coding situation?

Here, it's done for you: http://vb.mvps.org/samples/NetGrab
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
19 Mar 2009 6:50 PM
Faraz Azhar
Yes yes thats exactly what I've been trying to do; thank you both
Eduardo and Karl.
Author
21 Mar 2009 7:33 AM
Faraz Azhar
>
> Here, it's done for you:http://vb.mvps.org/samples/NetGrab
> --
> .NET: It's About Trust!
>  http://vfred.mvps.org

Does the NetGrab work behind proxy?
Author
23 Mar 2009 4:36 AM
Faraz Azhar
On Mar 21, 12:33 pm, Faraz Azhar <itzfa***@gmail.com> wrote:
> > Here, it's done for you:http://vb.mvps.org/samples/NetGrab
> > --
> > .NET: It's About Trust!
> >  http://vfred.mvps.org
>
> Does the NetGrab work behind proxy?

yea i experimented, it works. But it uses the IE's built-in settings
for proxy. If proxy is turned on by IE, the usercontrol's asyncread
method will use it too.
Anyways thanks a million everyone!