Modules talking to Forms

mattkw80

Well-known member
Joined
Jan 3, 2008
Messages
49
Location
Ontario, Canada
Programming Experience
Beginner
Is there a spot on this forum for newbies?

Like an "ask anything, no matter how stupid" area, like some forums have?


If so, I can re ask this in that area, but my question is....

Why can't my code within a module talk to controls on a form ?

I've got SUB's in modules, that I want to call subs in a form, but it just wont.

Any ideas ?
 
Members of modules are shared, same as explicitly declaring a member of a class shared. Shared members have no knowledge of any instance unless you tell them about it. Your form is not shared, an instance of it has to be created for it to be used. If you want the shared method to do something with a form instance you have to tell it which instance.
 
You can for example use a parameter of the method to give it the information it needs.
 
I'm sorry, I am trying to understand, but still don't.

If my form was called FORM1 and my module was called MODULE1

could you give me an example of what code I would need to use ?
 
In your sub or function that's in the module, if it needs to know about a textbox or combobox then you need to pass a textbox or combobox into the sub or function as a reference
 
I figured it out.

I appreciate your attempt to help, but I still don't understand what you are explaining.


What I want to do is extremely simple, and can be done in a few easy steps.

What you are explaining is greek to me.


Thanks anyway.


Matt
 
Perhaps this example helps:
VB.NET:
Public Class Utils
  Public Shared Sub TextTheTextBox(WhatTextBox as TextBox, TheText As String)
    WhatTextBox.Text = TheText
  End Sub
End Class
caller:
VB.NET:
Utils.TextTheTextBox(Me.HelloTextBox, "hello")
 
Back
Top