PC Review


Reply
Thread Tools Rate Thread

Accessing form controls from mudules

 
 
Bob
Guest
Posts: n/a
 
      24th Aug 2005
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


 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      24th Aug 2005
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
 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      24th Aug 2005
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


 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      24th Aug 2005
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


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      24th Aug 2005
"Bob" <(E-Mail Removed)> 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

 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      25th Aug 2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing controls on another form =?Utf-8?B?dmJ0cnlpbmc=?= Microsoft C# .NET 3 31st Aug 2007 03:39 PM
Accessing controls in another form DaveG Microsoft Dot NET 3 30th Apr 2005 10:46 PM
accessing form controls in Vb.net Deepa Yamini S Microsoft Dot NET Framework Forms 6 21st Oct 2004 11:08 PM
ACCESSING SUB FORM CONTROLS in adp =?Utf-8?B?Ui5ELkNIRVRUWQ==?= Microsoft Access Forms 5 23rd May 2004 04:24 PM
accessing controls on another form cm@gowcity Microsoft C# .NET 2 4th Mar 2004 09:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 PM.