By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

executing form.sub from a module

P: n/a
Hello,

I'm trying to put sub that's shared between all forms in my app in module so
when I make change I just change it one time.

This sub should execute and then invoke sub defaults() that's different for
each form and is contained within the forms. You'll probably ask why don't I
just put it in the form after the call to module.function, well it's a
handler for one combobox so technically I don't call it.

I made a reference to mainform form and then did
Module sharedFunction
Friend Sub cbo_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
'do something
frmMainForm.ActiveMdiChild.Defaults()
End Function
End Module

but I'm getting error message in Visual Studio .Net "C:\Visual
Studio\blabla\functions.vb(267): 'Defaults' is not a member of
'System.Windows.Forms.Form'."
the program executes ok and it does call sub properly but every time I want
to recompile I'm getting build error warning.

btw... sub name (Defaults) is same on each of the forms.
Thanks in advance ...
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Create a MyDefaults Interface with a Sub Defaults

Add the line Implements MyDefaults to each form's class

Then in your shared cbo_KeyUp sub, use CType(frmMainForm.ActiveMdiChild,
MyDefaults).Defaults()

e.g.

Public Class Form1
Inherits System.Windows.Forms.Form
Implements MyDefaults

Public Sub Defaults() Implements MyDefaults.Defaults
'your custom form specific code here
End Sub
End Class

Public Interface MyDefaults
Sub Defaults()
End Interface

Module sharedFunction
Public frmMainForm As FormMain
Friend Sub cbo_KeyUp(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
'do something
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults()
End Sub
End Module
"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:em****************@TK2MSFTNGP15.phx.gbl...
Hello,

I'm trying to put sub that's shared between all forms in my app in module
so when I make change I just change it one time.

This sub should execute and then invoke sub defaults() that's different
for each form and is contained within the forms. You'll probably ask why
don't I just put it in the form after the call to module.function, well
it's a handler for one combobox so technically I don't call it.

I made a reference to mainform form and then did
Module sharedFunction
Friend Sub cbo_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
'do something
frmMainForm.ActiveMdiChild.Defaults()
End Function
End Module

but I'm getting error message in Visual Studio .Net "C:\Visual
Studio\blabla\functions.vb(267): 'Defaults' is not a member of
'System.Windows.Forms.Form'."
the program executes ok and it does call sub properly but every time I
want to recompile I'm getting build error warning.

btw... sub name (Defaults) is same on each of the forms.
Thanks in advance ...

Nov 21 '05 #2

P: n/a
This is not going to help because I can't call this from module:

CType(frmMainForm.ActiveMdiChild, MyDefaults)

Just like I said, I have different forms calling this sub and in this case
MyDefaults will be bunch of different forms.

Even if I don't involve interfaces I'm able to call
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults() from the Module but
as I explained, I'm not able to CType to specific form.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
Create a MyDefaults Interface with a Sub Defaults

Add the line Implements MyDefaults to each form's class

Then in your shared cbo_KeyUp sub, use CType(frmMainForm.ActiveMdiChild,
MyDefaults).Defaults()

e.g.

Public Class Form1
Inherits System.Windows.Forms.Form
Implements MyDefaults

Public Sub Defaults() Implements MyDefaults.Defaults
'your custom form specific code here
End Sub
End Class

Public Interface MyDefaults
Sub Defaults()
End Interface

Module sharedFunction
Public frmMainForm As FormMain
Friend Sub cbo_KeyUp(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
'do something
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults()
End Sub
End Module
"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:em****************@TK2MSFTNGP15.phx.gbl...
Hello,

I'm trying to put sub that's shared between all forms in my app in module
so when I make change I just change it one time.

This sub should execute and then invoke sub defaults() that's different
for each form and is contained within the forms. You'll probably ask why
don't I just put it in the form after the call to module.function, well
it's a handler for one combobox so technically I don't call it.

I made a reference to mainform form and then did
Module sharedFunction
Friend Sub cbo_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
'do something
frmMainForm.ActiveMdiChild.Defaults()
End Function
End Module

but I'm getting error message in Visual Studio .Net "C:\Visual
Studio\blabla\functions.vb(267): 'Defaults' is not a member of
'System.Windows.Forms.Form'."
the program executes ok and it does call sub properly but every time I
want to recompile I'm getting build error warning.

btw... sub name (Defaults) is same on each of the forms.
Thanks in advance ...


Nov 21 '05 #3

P: n/a
You are not casting to a specifc form, you are casting each form that
implements the interface to an object that implements that interface. You
could even test each form to see see if it implements that interface using
If frmMainForm.ActiveMdiChild Is TypeOf MyDefault Then.

All of the forms will implement that interface and therefore have a Defaults
sub.

MyDefaults is the name of the Interface you define, I just used that one as
an example.

If you don't believe me, do a proof of concept test of this pattern.

"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:ex*************@TK2MSFTNGP10.phx.gbl...
This is not going to help because I can't call this from module:

CType(frmMainForm.ActiveMdiChild, MyDefaults)

Just like I said, I have different forms calling this sub and in this case
MyDefaults will be bunch of different forms.

Even if I don't involve interfaces I'm able to call
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults() from the Module
but as I explained, I'm not able to CType to specific form.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
Create a MyDefaults Interface with a Sub Defaults

Add the line Implements MyDefaults to each form's class

Then in your shared cbo_KeyUp sub, use CType(frmMainForm.ActiveMdiChild,
MyDefaults).Defaults()

e.g.

Public Class Form1
Inherits System.Windows.Forms.Form
Implements MyDefaults

Public Sub Defaults() Implements MyDefaults.Defaults
'your custom form specific code here
End Sub
End Class

Public Interface MyDefaults
Sub Defaults()
End Interface

Module sharedFunction
Public frmMainForm As FormMain
Friend Sub cbo_KeyUp(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
'do something
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults()
End Sub
End Module
"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:em****************@TK2MSFTNGP15.phx.gbl...
Hello,

I'm trying to put sub that's shared between all forms in my app in
module so when I make change I just change it one time.

This sub should execute and then invoke sub defaults() that's different
for each form and is contained within the forms. You'll probably ask why
don't I just put it in the form after the call to module.function, well
it's a handler for one combobox so technically I don't call it.

I made a reference to mainform form and then did
Module sharedFunction
Friend Sub cbo_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
'do something
frmMainForm.ActiveMdiChild.Defaults()
End Function
End Module

but I'm getting error message in Visual Studio .Net "C:\Visual
Studio\blabla\functions.vb(267): 'Defaults' is not a member of
'System.Windows.Forms.Form'."
the program executes ok and it does call sub properly but every time I
want to recompile I'm getting build error warning.

btw... sub name (Defaults) is same on each of the forms.
Thanks in advance ...



Nov 21 '05 #4

P: n/a
You are correct and yes, it does work :)

Had problems yesterday as I put definition for interface within the class so
it was giving me error.
Thank you very much ...

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
You are not casting to a specifc form, you are casting each form that
implements the interface to an object that implements that interface. You
could even test each form to see see if it implements that interface using
If frmMainForm.ActiveMdiChild Is TypeOf MyDefault Then.

All of the forms will implement that interface and therefore have a
Defaults sub.

MyDefaults is the name of the Interface you define, I just used that one
as an example.

If you don't believe me, do a proof of concept test of this pattern.

"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:ex*************@TK2MSFTNGP10.phx.gbl...
This is not going to help because I can't call this from module:

CType(frmMainForm.ActiveMdiChild, MyDefaults)

Just like I said, I have different forms calling this sub and in this
case MyDefaults will be bunch of different forms.

Even if I don't involve interfaces I'm able to call
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults() from the Module
but as I explained, I'm not able to CType to specific form.

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
Create a MyDefaults Interface with a Sub Defaults

Add the line Implements MyDefaults to each form's class

Then in your shared cbo_KeyUp sub, use CType(frmMainForm.ActiveMdiChild,
MyDefaults).Defaults()

e.g.

Public Class Form1
Inherits System.Windows.Forms.Form
Implements MyDefaults

Public Sub Defaults() Implements MyDefaults.Defaults
'your custom form specific code here
End Sub
End Class

Public Interface MyDefaults
Sub Defaults()
End Interface

Module sharedFunction
Public frmMainForm As FormMain
Friend Sub cbo_KeyUp(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
'do something
CType(frmMainForm.ActiveMdiChild, MyDefaults).Defaults()
End Sub
End Module
"excelleinc.com" <vj******@excelleinc.com> wrote in message
news:em****************@TK2MSFTNGP15.phx.gbl...
Hello,

I'm trying to put sub that's shared between all forms in my app in
module so when I make change I just change it one time.

This sub should execute and then invoke sub defaults() that's different
for each form and is contained within the forms. You'll probably ask
why don't I just put it in the form after the call to module.function,
well it's a handler for one combobox so technically I don't call it.

I made a reference to mainform form and then did
Module sharedFunction
Friend Sub cbo_KeyUp(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
'do something
frmMainForm.ActiveMdiChild.Defaults()
End Function
End Module

but I'm getting error message in Visual Studio .Net "C:\Visual
Studio\blabla\functions.vb(267): 'Defaults' is not a member of
'System.Windows.Forms.Form'."
the program executes ok and it does call sub properly but every time I
want to recompile I'm getting build error warning.

btw... sub name (Defaults) is same on each of the forms.
Thanks in advance ...



Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.