467,911 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

Accessing form controls from mudules

Bob
Hello:

I have a form with 26 panels. Each panel has a bunch of other controls in
it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to true
and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code for the
buttons to a module for code organization.

Here is the code in the form I have for each button.

I tried creating a sub in the module and putting all this in in the sub

Module modPanels
Dim frm1 as Form1
frm1.Label01.Visible = True 'Raises an error. Not set to an instance of an
object. As New Form1 causes nothing to happen
frm1.Panel01.Visible = True

<Same for other panels> etc
End Module

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label01.Visible = True
Panel01.Visible = True

Panel02.Visible = False
Label02.Visible = False

Panel03.Visible = False
Label03.Visible = False

Panel04.Visible = False
Label04.Visible = False

Panel05.Visible = False
Label05.Visible = False

Panel06.Visible = False
Label06.Visible = False

Panel07.Visible = False
Label07.Visible = False

Panel08.Visible = False
Label08.Visible = False

Panel09.Visible = False
Label09.Visible = False

Panel10.Visible = False
Label010.Visible = False

Me.Panel11.Visible = False
Me.Label011.Visible = False

Me.Panel12.Visible = False
Me.Label012.Visible = False

Me.Panel13.Visible = False
Me.Label013.Visible = False

Me.Panel14.Visible = False
Me.Label014.Visible = False

Me.Panel15.Visible = False
Me.Label015.Visible = False

Me.Panel16.Visible = False
Me.Label016.Visible = False

Me.Panel17.Visible = False
Me.Label017.Visible = False

Me.Panel18.Visible = False
Me.Label018.Visible = False

Me.Panel19.Visible = False
Me.Label019.Visible = False

Me.Panel20.Visible = False
Me.Label020.Visible = False

Me.Panel21.Visible = False
Me.Label021.Visible = False

Me.Panel22.Visible = False
Me.Label022.Visible = False

Me.Panel23.Visible = False
Me.Label023.Visible = False

Me.Panel24.Visible = False
Me.Label024.Visible = False

Me.Panel25.Visible = False
Me.Label025.Visible = False

Me.Panel26.Visible = False
Me.Label026.Visible = False
End Sub

TIA

Bob
Nov 21 '05 #1
  • viewed: 1048
Share:
9 Replies
Bob wrote:
Hello:

I have a form with 26 panels. Each panel has a bunch of other controls in
it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to true
and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code for the
buttons to a module for code organization.

Here is the code in the form I have for each button.

I tried creating a sub in the module and putting all this in in the sub

Module modPanels
Dim frm1 as Form1
frm1.Label01.Visible = True 'Raises an error. Not set to an instance of an
object. As New Form1 causes nothing to happen
frm1.Panel01.Visible = True

<Same for other panels> etc
End Module

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label01.Visible = True
Panel01.Visible = True

Panel02.Visible = False
Label02.Visible = False

Panel03.Visible = False
Label03.Visible = False

Panel04.Visible = False
Label04.Visible = False

Panel05.Visible = False
Label05.Visible = False

Panel06.Visible = False
Label06.Visible = False

Panel07.Visible = False
Label07.Visible = False

Panel08.Visible = False
Label08.Visible = False

Panel09.Visible = False
Label09.Visible = False

Panel10.Visible = False
Label010.Visible = False

Me.Panel11.Visible = False
Me.Label011.Visible = False

Me.Panel12.Visible = False
Me.Label012.Visible = False

Me.Panel13.Visible = False
Me.Label013.Visible = False

Me.Panel14.Visible = False
Me.Label014.Visible = False

Me.Panel15.Visible = False
Me.Label015.Visible = False

Me.Panel16.Visible = False
Me.Label016.Visible = False

Me.Panel17.Visible = False
Me.Label017.Visible = False

Me.Panel18.Visible = False
Me.Label018.Visible = False

Me.Panel19.Visible = False
Me.Label019.Visible = False

Me.Panel20.Visible = False
Me.Label020.Visible = False

Me.Panel21.Visible = False
Me.Label021.Visible = False

Me.Panel22.Visible = False
Me.Label022.Visible = False

Me.Panel23.Visible = False
Me.Label023.Visible = False

Me.Panel24.Visible = False
Me.Label024.Visible = False

Me.Panel25.Visible = False
Me.Label025.Visible = False

Me.Panel26.Visible = False
Me.Label026.Visible = False
End Sub

TIA

Bob


You never created an instance of Form1

dim frm1 as new Form1

Otherwise frm1 is just a pointer to nothing.

Chris
Nov 21 '05 #2
Bob
I did

Here is what I tried and nothing happens. Not even an error
Module modPanels
Sub Panel2()
Dim frm1 As New Form1

frm1.Label01.Visible = False
frm1.Panel01.Visible = False

frm1.Panel02.Visible = True
frm1.Label02.Visible = True

frm1.Panel03.Visible = False
frm1.Label03.Visible = False

frm1.Panel04.Visible = False
frm1.Label04.Visible = False

frm1.Panel05.Visible = False
frm1.Label05.Visible = False

frm1.Panel06.Visible = False
frm1.Label06.Visible = False

frm1.Panel07.Visible = False
frm1.Label07.Visible = False

frm1.Panel08.Visible = False
frm1.Label08.Visible = False

frm1.Panel09.Visible = False
frm1.Label09.Visible = False

frm1.Panel10.Visible = False
frm1.Label010.Visible = False

frm1.Panel11.Visible = False
frm1.Label011.Visible = False

frm1.Panel12.Visible = False
frm1.Label012.Visible = False

frm1.Panel13.Visible = False
frm1.Label013.Visible = False

frm1.Panel14.Visible = False
frm1.Label014.Visible = False

frm1.Panel15.Visible = False
frm1.Label015.Visible = False

frm1.Panel16.Visible = False
frm1.Label016.Visible = False

frm1.Panel17.Visible = False
frm1.Label017.Visible = False

frm1.Panel18.Visible = False
frm1.Label018.Visible = False

frm1.Panel19.Visible = False
frm1.Label019.Visible = False

frm1.Panel20.Visible = False
frm1.Label020.Visible = False

frm1.Panel21.Visible = False
frm1.Label021.Visible = False

frm1.Panel22.Visible = False
frm1.Label022.Visible = False

frm1.Panel23.Visible = False
frm1.Label023.Visible = False

frm1.Panel24.Visible = False
frm1.Label024.Visible = False

frm1.Panel25.Visible = False
frm1.Label025.Visible = False

frm1.Panel26.Visible = False
frm1.Label026.Visible = False
End Sub
End Module
Then in my buttons click event in the Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
modPanels.Panel2()
End Sub
Nov 21 '05 #3
Bob wrote:
I did

Here is what I tried and nothing happens. Not even an error
Module modPanels
Sub Panel2()
Dim frm1 As New Form1

frm1.Label01.Visible = False
frm1.Panel01.Visible = False

frm1.Panel02.Visible = True
frm1.Label02.Visible = True

frm1.Panel03.Visible = False
frm1.Label03.Visible = False

frm1.Panel04.Visible = False
frm1.Label04.Visible = False

frm1.Panel05.Visible = False
frm1.Label05.Visible = False

frm1.Panel06.Visible = False
frm1.Label06.Visible = False

frm1.Panel07.Visible = False
frm1.Label07.Visible = False

frm1.Panel08.Visible = False
frm1.Label08.Visible = False

frm1.Panel09.Visible = False
frm1.Label09.Visible = False

frm1.Panel10.Visible = False
frm1.Label010.Visible = False

frm1.Panel11.Visible = False
frm1.Label011.Visible = False

frm1.Panel12.Visible = False
frm1.Label012.Visible = False

frm1.Panel13.Visible = False
frm1.Label013.Visible = False

frm1.Panel14.Visible = False
frm1.Label014.Visible = False

frm1.Panel15.Visible = False
frm1.Label015.Visible = False

frm1.Panel16.Visible = False
frm1.Label016.Visible = False

frm1.Panel17.Visible = False
frm1.Label017.Visible = False

frm1.Panel18.Visible = False
frm1.Label018.Visible = False

frm1.Panel19.Visible = False
frm1.Label019.Visible = False

frm1.Panel20.Visible = False
frm1.Label020.Visible = False

frm1.Panel21.Visible = False
frm1.Label021.Visible = False

frm1.Panel22.Visible = False
frm1.Label022.Visible = False

frm1.Panel23.Visible = False
frm1.Label023.Visible = False

frm1.Panel24.Visible = False
frm1.Label024.Visible = False

frm1.Panel25.Visible = False
frm1.Label025.Visible = False

frm1.Panel26.Visible = False
frm1.Label026.Visible = False
End Sub
End Module
Then in my buttons click event in the Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
modPanels.Panel2()
End Sub


You never show the form.
Chris
frm.showdialog()
Nov 21 '05 #4
Bob
Chris:

Form1 is already open. Thats the form that has the button on it. Putting
frm1.showdialog() in the Module opens another Form1

TIA

Bob
Nov 21 '05 #5
"Bob" <Ye*******@nospam.net> schrieb
Hello:

I have a form with 26 panels. Each panel has a bunch of other
controls in it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to
true and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code
for the buttons to a module for code organization.


"Organization"? Don't do it as it's often considered bad design. Why don't
you keep it in the Form? If you need the code multiple times, put all
controls onto a usercontrol and place it on as many forms as you need.
Armin

Nov 21 '05 #6
Bob wrote:
Chris:

Form1 is already open. Thats the form that has the button on it. Putting
frm1.showdialog() in the Module opens another Form1

TIA

Bob


Well, you created a new version of Form1, so I assumed you wanted to
show it. If you are trying to access properties on Form1 from the
Module you need to have a reference to the current form....

something like:

Public Sub TestModule(frm1 as Form1)

.... do something on frm1

End Sub

From inside Form1

Private Sub ....
TestModule(me)
End Sub

But my question then becomes why even put this in a module, since you
are acting on frm1, then put the code in frm1, that's why it is a class....

Chris
Nov 21 '05 #7
Bob
Chris:

Thanks. That did it.
But my question then becomes why even put this in a module, since you are
acting on frm1, then put the code in frm1, that's why it is a class....


Yeah someone else said that. I just wanted to break some of that code out of
the form for organization. Is it a performance hit? I'm just using a
standerd module. Not a class mod.

here is the code I wanted to get out of the main form.
http://www.are-hosting.com/panelcode.asp
My skills will improve in time. Maybe when you go to that link, you'll
still think I'm wasting time. Plus it's good experience however trivial it
might be. Gotta start somewhere.

I will be accessing it from other controles later too. There probably is a
better way but if I knew that, I wouldn't be asking for answers to basic
stuff like what you helped me with. I need more experience. I read up on
passing arguments and actually build some functions in VB 6 but that one
eluded me.

Thanks for the help.

Bob
Nov 21 '05 #8
Bob
Armin:

Why not? Chris's tip seems to be working ok. Someday I'll get to the
chapter on user controles. Right now I can only read when I'm on the
toilet. :)

Thanks

Bob
Nov 21 '05 #9
Bob
Armin:

Look at this

http://www.are-hosting.com/panelcode.asp

Bob
Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jim Heavey | last post: by
6 posts views Thread by arvee | last post: by
3 posts views Thread by Tim Fitzgerald | last post: by
3 posts views Thread by judy.j.miller | last post: by
8 posts views Thread by colmkav | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.