PC Review


Reply
Thread Tools Rate Thread

Re: "variable undeclared/never assigned" error on "Public Shared" Panel Control

 
 
VB Programmer
Guest
Posts: n/a
 
      20th Oct 2003
BTW, the panKnob actually has a label and an ActiveX control inside of it.
It is THESE controls that I really want to have access to. And, yes, I DID
make them also Public Shared.

Thanks.

"VB Programmer" <growNO-(E-Mail Removed)> wrote in message news:...
> I wanted to access some properties of a panel control that is on a

different
> form. So, I went to the (Declarations) section of my main form (the form
> with the panel) and changed the panel (called "panKnob") from "Friend
> WithEvents" to "Public Shared WithEvents" so that I could access it from
> another class (i.e. frmMain.panKnob.Visible=True")
>
> I get this build error:
> "The variable 'panKnob' is either undeclared or was never assigned."
>
> Double clicking on it takes me to frmMain.InitializeComponent. The line

is:
> Me.Controls.Add(Me.panKnob)
>
> Any ideas? What is the best way to do this?
>
>



 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      20th Oct 2003
"VB Programmer" <growNO-(E-Mail Removed)> schrieb
> BTW, the panKnob actually has a label and an ActiveX control inside
> of it. It is THESE controls that I really want to have access to.
> And, yes, I DID make them also Public Shared.


We mustn't change the code generated by the designer. You can't create
shared controls by the designer.


--
Armin

 
Reply With Quote
 
 
 
 
VB Programmer
Guest
Posts: n/a
 
      20th Oct 2003
Thanks. I gues I have to do it something like this:

Dim MyForm as new frmMain
MyForm.MyCtrl.Value = 3

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "VB Programmer" <growNO-(E-Mail Removed)> schrieb
> > BTW, the panKnob actually has a label and an ActiveX control inside
> > of it. It is THESE controls that I really want to have access to.
> > And, yes, I DID make them also Public Shared.

>
> We mustn't change the code generated by the designer. You can't create
> shared controls by the designer.
>
>
> --
> Armin
>



 
Reply With Quote
 
e
Guest
Posts: n/a
 
      21st Oct 2003
Are you starting your project via frmMain, or a startup module containing
Sub Main?

"VB Programmer" <growNO-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks. I gues I have to do it something like this:
>
> Dim MyForm as new frmMain
> MyForm.MyCtrl.Value = 3
>
> "Armin Zingler" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > "VB Programmer" <growNO-(E-Mail Removed)> schrieb
> > > BTW, the panKnob actually has a label and an ActiveX control inside
> > > of it. It is THESE controls that I really want to have access to.
> > > And, yes, I DID make them also Public Shared.

> >
> > We mustn't change the code generated by the designer. You can't create
> > shared controls by the designer.
> >
> >
> > --
> > Armin
> >

>
>



 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      21st Oct 2003
Hi VBP,

The Windows Form Designer generated code is <not>, as Armin states, a
'mustn't touch' area. It is <recommended> that you avoid doing anything in
that area. Articles on MSDN actually advise making changes there in certain
circumstances.

The reasons against are two-fold. The first is to save you losing changes.
The second is so that you don't confuse the Designer.

To explore your problem, I made a Form with a Panel and a Label, Button
and AxBrowser inside the Panel. I then changed them all to Public and rebuilt
the Solution. No problem. To test whether having an event handlers might make
a difference, I double clicked each to get create the defaults. This turned
the Public of the Panel back to Friend. The other Controls stayed Public.

That's the first reason why changes are not recommended - they <may> be
lost if you subsequently make alterations <in the Designer>. But if you never
change the Form using the Designer, it won't regenerate the code and lose your
changes.

The second reason is more important and the Designer will let you know in
no uncertain terms. There are two occasions on which InitializeComponent() is
required. On the second occasion - runtime - the compiled method is executed
like all other code in the app. On the first occasion - when the Form is
loaded at Design-time - the code is <not> executed. Rather, the Designer
<interprets> InitializeComponent(). This is easy enough - <it> created it so
it knows what to expect. Unfortunately, you can make code changes that look
like perfectly valid and compilable code but the Designer is unable to work
out how to interpret them.

Changing Friend to Public is one of the changes that the Designer <can>
recognise. Adding a call to another method in your Form is one that it can't.

Like I said, I created a simple duplication of your problem and the
Solution rebuilt perfectly. There may be another reason why you get the error.

However, I would tend to use a ReadOnly Public property which gives access
to the Label and ActiveX Controls. This will keep the code out of the
Designer area - no later developer can inadvertantly cause the Friend to
Public change to be undone; and the subtle difference in behaviour is not
hidden away in autogenerated code. The use of Properties will effectively
document the importance of access to these Controls. And lastly, although
you're a better programmer than that ;-), the other Form would not be able to
make any change to these Controls themselves - only to their properties.

Regards,
Fergus


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      21st Oct 2003
"Fergus Cooney" <(E-Mail Removed)> schrieb
> The Windows Form Designer generated code is <not>, as Armin
> states, a
> 'mustn't touch' area. It is <recommended> that you avoid doing
> anything in that area. Articles on MSDN actually advise making
> changes there in certain circumstances.
> [...]


Didn't read your whole story..... but I'd never touch the generated code.
Maybe I wasn't as exact as I should have been: Don't touch
Initializecomponent. Of course, you can add code to the constructor.


--
Armin

 
Reply With Quote
 
VB Programmer
Guest
Posts: n/a
 
      21st Oct 2003
I would like to start with sub Main, but when I did this the app closed
immediately after running sub Main.

"e" <(E-Mail Removed)> wrote in message news:c7ydneBSy6be9wmiRVn-(E-Mail Removed)...
> Are you starting your project via frmMain, or a startup module containing
> Sub Main?
>
> "VB Programmer" <growNO-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thanks. I gues I have to do it something like this:
> >
> > Dim MyForm as new frmMain
> > MyForm.MyCtrl.Value = 3
> >
> > "Armin Zingler" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > "VB Programmer" <growNO-(E-Mail Removed)> schrieb
> > > > BTW, the panKnob actually has a label and an ActiveX control inside
> > > > of it. It is THESE controls that I really want to have access to.
> > > > And, yes, I DID make them also Public Shared.
> > >
> > > We mustn't change the code generated by the designer. You can't create
> > > shared controls by the designer.
> > >
> > >
> > > --
> > > Armin
> > >

> >
> >

>
>



 
Reply With Quote
 
e
Guest
Posts: n/a
 
      21st Oct 2003
Oh, then I think that's part of your problem is that frmMain simply isn't
accessible from your other forms in the way you want it to be. You'll
probably wanna do something like this (it'll show you how to keep your
program running from a sub main start). Here's an example of a startup
module that contains sub main

....

'Public declaration of the main form so everyone can see it
Public MainForm as new frmMain

Sub Main()

MainForm.Show
Application.Run()

End Sub

....

Because MainForm is declared as 'Public' in the startup module, any form in
your application can now reference MainForm & it's public controls. That
Application.Run line is essentially required to have vb.net programs run.

Once you get that in place, and the app runs from a startup module, go into
the designer for frmMain and adjust the 'Modifier' property of the activeX
control and the label you want to access from other forms from 'Friend' to
'Public'. You might want to remove and re-add the controls in the designer,
to sort of clean up any mess that's been made of their designer code.

From the other form (which I don't know the name of and assume frmMain at
some point creates and shows?), you should be able to reference frmMain and
the public controls on frmMain. For instance from the other form, this
should work:

MainForm.ThePublicLabel.Text = "this was changed from another form"
MainForm.ThePublicActiveXControl.SomeProperty = SomeValue

You shouldn't really have to touch the scope of the panel at all, I wouldn't
think. Eh but if you do, just make it 'Public' with it's Modifiers property
in the designer just like you did with the label and the activex control.

"VB Programmer" <growNO-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I would like to start with sub Main, but when I did this the app closed
> immediately after running sub Main.
>
> "e" <(E-Mail Removed)> wrote in message

news:c7ydneBSy6be9wmiRVn-(E-Mail Removed)...
> > Are you starting your project via frmMain, or a startup module

containing
> > Sub Main?
> >
> > "VB Programmer" <growNO-(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Thanks. I gues I have to do it something like this:
> > >
> > > Dim MyForm as new frmMain
> > > MyForm.MyCtrl.Value = 3
> > >
> > > "Armin Zingler" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > "VB Programmer" <growNO-(E-Mail Removed)> schrieb
> > > > > BTW, the panKnob actually has a label and an ActiveX control

inside
> > > > > of it. It is THESE controls that I really want to have access to.
> > > > > And, yes, I DID make them also Public Shared.
> > > >
> > > > We mustn't change the code generated by the designer. You can't

create
> > > > shared controls by the designer.
> > > >
> > > >
> > > > --
> > > > Armin
> > > >
> > >
> > >

> >
> >

>
>



 
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
add shadow to panel control, panel control opacity nondos Microsoft VB .NET 1 6th Aug 2007 07:30 PM
Hide control panel from Start menu / My PC / Control Panel Avatar_e Windows XP General 4 20th Jun 2006 07:43 PM
How to hide Control Panel, or tools in Control Panel Tony Windows XP General 3 22nd Mar 2006 04:41 PM
is there an event that fires when a child control is added to a parent container control (ie child panel added to a parent panel)? notu Microsoft Dot NET Compact Framework 1 19th Jul 2005 07:34 PM
Removal of Control Panel Icon, specifically : Wild Tangent Control Panel Pungconk Windows XP New Users 3 31st Dec 2003 06:23 PM


Features
 

Advertising
 

Newsgroups
 


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