Module Control Addressing in VB.Net

  • Thread starter Thread starter Brent McIntyre
  • Start date Start date
B

Brent McIntyre

Good evening all,

I am going crazy with a problem that I am sure has a simple solution.

I need to add items to a ComboBox on a Form. I can do it simply when I
code on form.vb, but when go to a procedure on a seperate module it says
"Name 'ComboBox' is not declared". I have tried setting the modifiers
for the ComboBox to Public, Friend and Private all to no avail. I am
also not sure why on the main page "Me." is used before a control, I
tried this on the module but it didn't work.

Any help you may be able to provide would be much appreciated as I am
still trying to learn this language.

Yours sincerely,

Brent McIntyre
 
Hello,

Brent McIntyre said:
I am going crazy with a problem that I am sure has a simple
solution.

I need to add items to a ComboBox on a Form. I can
do it simply when I code on form.vb, but when go to
a procedure on a seperate module it says "Name
'ComboBox' is not declared".

You must pass a reference to the control, for example in a parameter:

\\\
Imports System.Windows.Forms

Public Module MyModule
Public Sub Bla(ByVal Foo As ComboBox)
Foo.Items.Add(...)
End Sub
End Module
///

Usage (in the form):

\\\
MyModule.Bla(Me.ComboBox1)
///
 
Brent McIntyre said:
I am going crazy with a problem that I am sure has a simple
solution.

I need to add items to a ComboBox on a Form. I can do it simply when
I code on form.vb, but when go to a procedure on a seperate module it
says "Name 'ComboBox' is not declared". I have tried setting the
modifiers for the ComboBox to Public, Friend and Private all to no
avail. I am also not sure why on the main page "Me." is used before
a control, I tried this on the module but it didn't work.

Any help you may be able to provide would be much appreciated as I
am still trying to learn this language.

The Combobox is a property of the Form. If you want to access a property of
an object, you need a reference to the object. If you don't have a reference
you have to pass it to the Module.
 
OOP is a bitch sometimes. Herfried is exactly right. You really have
to watch that cause variables are objects aswell.

The only thing I've never figured out is in an MDI environment, how to
reference one child from another LOL

Just remember, everything's an object and all objects have to be
referenced/declared somewhere somehow :)

Tibby
 
Back
Top