Windows Develop Bookmark and Share   
 index > Windows Forms Designer > The variable 'Control Name' is either undeclared or was never assigned
 

The variable 'Control Name' is either undeclared or was never assigned

Hi All,

This is an old problem in VS2003, but still repeats in VS2005.
My project has a Windows form.  The project is working fine and the EXE is still running like a champ.  But whenever I open the form using the VS2005 IDE designer, I got the following error:

The variable 'ucMainPanel' is either undeclared or was never assigned.
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

I searched the Internet and got this article:
http://support.microsoft.com/?kbid=842706

The article leads me to a page where it has a technical support phone number.  I call the number and talked to a MS technical support personnel.  He told me that MS only support VS2003 now, and the professional technical support people only work on weekday.

Does anyone run into the same problem I am having?  What do I have to do to solve this problem?

Thanks in advance.
DQ
David N_2  Sunday, May 01, 2005 11:09 PM
First off, what version of 2005 are you using?  Is it Beta 2?  If not, please try to reproduce the problem on Beta 2.  If it still fails on beta 2, please attach your project and open an MSDN product feedback bug for it and we'll take a look.

http://lab.msdn.microsoft.com/ProductFeedback/

thanks
 -- mike
Mike Harsh  Thursday, May 05, 2005 9:36 PM
It is beta 2.  And I figure out what is the problem.

The VS2005 IDE try to load the application bmp files in its very own directory.  Most of my forms use some bmp file.  And my code is designed to load the bmp files from the "All users\Application data\MY_PROGRAM\*.BMP"

Of-course, the code tries to get the full path name of the MY_PROGRAM dynamically at runtime (who wants to hard-code it any way?).  It works perfectly when I run my program.

The problem is that the VS2005 designer also tries to load those bmp files at its own runtime, and when it cannot load the files, if it gives the users (me) a clear message such as "Cannot load file xxxx.bmp from the folder C:\Documents and Settings\All Users\Application Data\Microsoft® Visual Studio® 2005", everyone could figure out what is wrong in 5 seconds.

Instead, it could not display the form (even though it still can display it without those bmp files) and displays a message that leads everyone to confusion and frustration.

DQ
David N_2  Monday, May 09, 2005 4:34 AM
First off, what version of 2005 are you using?  Is it Beta 2?  If not, please try to reproduce the problem on Beta 2.  If it still fails on beta 2, please attach your project and open an MSDN product feedback bug for it and we'll take a look.

http://lab.msdn.microsoft.com/ProductFeedback/

thanks
 -- mike
Mike Harsh  Thursday, May 05, 2005 9:36 PM
It is beta 2.  And I figure out what is the problem.

The VS2005 IDE try to load the application bmp files in its very own directory.  Most of my forms use some bmp file.  And my code is designed to load the bmp files from the "All users\Application data\MY_PROGRAM\*.BMP"

Of-course, the code tries to get the full path name of the MY_PROGRAM dynamically at runtime (who wants to hard-code it any way?).  It works perfectly when I run my program.

The problem is that the VS2005 designer also tries to load those bmp files at its own runtime, and when it cannot load the files, if it gives the users (me) a clear message such as "Cannot load file xxxx.bmp from the folder C:\Documents and Settings\All Users\Application Data\Microsoft® Visual Studio® 2005", everyone could figure out what is wrong in 5 seconds.

Instead, it could not display the form (even though it still can display it without those bmp files) and displays a message that leads everyone to confusion and frustration.

DQ
David N_2  Monday, May 09, 2005 4:34 AM

I get the same kind of error. Further on in the thread the resolution seems to have something to do with the bitmap files that the control is using. I have no such controls. I have not been able to find a solution.

Me.dgOrderItems = New ucOrderItemGrid(New DataGridEditTextBoxColumn.ChangedCellEventHandler(AddressOf CheckTableChange))

'Me.dgOrderItems = New System.Windows.Forms.DataGrid

If I uncomment the line above using the system DataGrid and comment the derived constructor then the designer comes up just fine.

Any suggestions?

Kevin

KevinBurton  Monday, June 19, 2006 5:25 PM

I have a Bug-proof of the error "The variable is either undeclared or was never assigned in VB.NET" and i am using VS2005 (not beta 2) you can checkit on this page http://www.velocityreviews.com/forums/t371868-vb2005-bugproof-the-variable-var-is-either-undeclared-or-was-never-assigned.html

Best regards,

Júlio Nobre

Júlio Nobre  Friday, May 11, 2007 11:24 AM

I too had this error in my environment. I do not know what caused this error whatsoever.

But I have a solution to this error. Remove the project which is giving the error and add it again to the solution.

Voila..! It compiles without any error/warnings

Regards,

Sangeetha

Sangeetha Viswanathan  Wednesday, July 02, 2008 12:57 PM

Same problem as stated above. I was using a third party control. Could not see the form anymore?? Removed the project from the solution and then added it back again.....it works!

d_augie  Wednesday, July 16, 2008 4:40 PM

I tried the remove project from solution then re-add and unfortunately it didn't work. The item that appears to be the problem is a control array, but it just gives me 'variable '_Label1_0' is either undeclared or was never assigned'. Any more ideas?

Thanx!

B

  • Proposed As Answer byJerJames Tuesday, April 28, 2009 5:07 PM
  •  
BradBum  Tuesday, September 30, 2008 8:19 PM
  • Proposed As Answer byJerJames Tuesday, April 28, 2009 5:13 PM
  •  
JerJames  Tuesday, April 28, 2009 5:13 PM
Here's another possibility. You have a custom control, and in a moment of temporary insanity, you remove the empty constructor, replacing it with one or more that require parameters. E.g. Used to have: Public Sub New() ... End Sub And you changed it to: Public Sub New(byval Foo as string) ... End Sub So now your nifty control has no default constructor. PRANG!!! The designer has one or more statements that need to instantiate your custom control -- but can't, because your control requires parms in its constructor, and the designer has no way of providing them. You may be tempted to edit the designer and supply the parms, but doooooooon't do it. Just go back and provide a default constructor.
Leigh Webber  Wednesday, September 02, 2009 9:44 PM

You can use google to search for other answers

Custom Search

More Threads

• How to use client area in derived forms
• Make sort kind of DataGridViewColumns when click on HeaderColumns
• Cannot access Index or Dynamic Help
• Can one prevent InitializeComponent to create (new...) a control ?
• Transparency Issue
• Repainting Controls
• Preventing OnDrawItem from being called?
• Newbie Question
• Doesnot show image in datagridview for the first time when set an MDIParent property
• Component