locked
The variable '<control_name>' is either undeclared or was never assigned. RRS feed

  • Question

  • I work on VS2008 Developement edition.

    I have developed a new textbox.

    In the same dll i use this new textbox. Sometimes when i try to view a form or a control that uses this new textbox i get the warning "The variable '<control_name>' is either undeclared or was never assigned." even though in the InitializeComponent the control is instantiated. Is there a way to solve this or determine why this warning appears. I don't want to change my controls beetween .net textbox and my textbox every time i want to see the IDE.

    The weird thing is that sometimes the warning does not appear but i don't know what have i done.

     

    Friday, April 2, 2010 9:22 AM

All replies

  • The reason for this error

    http://msdn.microsoft.com/en-us/library/4008y84t.aspx


    Thanks,
    A.m.a.L
    [MVP Visual C#]
    Dot Net Goodies
    Don't hate the hacker, hate the code
    Friday, April 2, 2010 10:14 AM
  • I already read that thread but my control is instantiated in the InitializeComponent. Doesn't the IDE use this method?
    Friday, April 2, 2010 11:10 AM
  • Hi ARHANGEL19,

    Could you please provide the code snippet in the InitializeComponent method?

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Wednesday, April 7, 2010 11:45 AM
  • Here is the method

    private void InitializeComponent()
    {
    	this.components = new System.ComponentModel.Container();
    	System.Windows.Forms.Panel panel1;
    	System.Windows.Forms.Panel panel3;
    	FormDesigner.Common.Pages.ToolStripEx toolStrip1;
    	System.Windows.Forms.Panel panel2;
    	this.tbVPConditions = new FormDesigner.Controls.AutoCompleteTextBox(this.components);
    	this.btnWizard = new System.Windows.Forms.ToolStripButton();
    	this.btnLibrary = new System.Windows.Forms.ToolStripDropDownButton();
    	this.tsSaveQuery = new System.Windows.Forms.ToolStripMenuItem();
    	this.tsUseQuery = new System.Windows.Forms.ToolStripMenuItem();
    	this.btnClear = new System.Windows.Forms.ToolStripButton();
    	this.textBox1 = new System.Windows.Forms.TextBox();
    	this.labelConditions = new System.Windows.Forms.Label();
    	this.labelType = new System.Windows.Forms.Label();
    	this.labelAction = new System.Windows.Forms.Label();
    	this.label2 = new System.Windows.Forms.Label();
    	this.label1 = new System.Windows.Forms.Label();
    	this.cbVPField = new System.Windows.Forms.ComboBox();
    	this.cbVPType = new System.Windows.Forms.ComboBox();
    	this.cbVPAction = new System.Windows.Forms.ComboBox();
    	this.groupBox1 = new System.Windows.Forms.GroupBox();
    	this.btnCancel = new System.Windows.Forms.Button();
    	this.btnOK = new System.Windows.Forms.Button();
    	panel1 = new System.Windows.Forms.Panel();
    	panel3 = new System.Windows.Forms.Panel();
    	toolStrip1 = new FormDesigner.Common.Pages.ToolStripEx();
    	panel2 = new System.Windows.Forms.Panel();
    	panel1.SuspendLayout();
    	panel3.SuspendLayout();
    	toolStrip1.SuspendLayout();
    	panel2.SuspendLayout();
    	this.groupBox1.SuspendLayout();
    	this.SuspendLayout();
    	// 
    	// panel1
    	// 
    	panel1.Controls.Add(panel3);
    	panel1.Controls.Add(panel2);
    	panel1.Dock = System.Windows.Forms.DockStyle.Fill;
    	panel1.Location = new System.Drawing.Point(2, 2);
    	panel1.Name = "panel1";
    	panel1.Size = new System.Drawing.Size(390, 370);
    	panel1.TabIndex = 0;
    	// 
    	// panel3
    	// 
    	panel3.Controls.Add(this.tbVPConditions);
    	panel3.Controls.Add(toolStrip1);
    	panel3.Dock = System.Windows.Forms.DockStyle.Fill;
    	panel3.Location = new System.Drawing.Point(0, 197);
    	panel3.Name = "panel3";
    	panel3.Size = new System.Drawing.Size(390, 173);
    	panel3.TabIndex = 2;
    	// 
    	// tbVPConditions
    	// 
    	this.tbVPConditions.AcceptsReturn = true;
    	this.tbVPConditions.AcceptsTab = true;
    	this.tbVPConditions.Dock = System.Windows.Forms.DockStyle.Fill;
    	this.tbVPConditions.ItemId = null;
    	this.tbVPConditions.Location = new System.Drawing.Point(0, 25);
    	this.tbVPConditions.ModuleId = null;
    	this.tbVPConditions.Multiline = true;
    	this.tbVPConditions.Name = "tbVPConditions";
    	this.tbVPConditions.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
    	this.tbVPConditions.Size = new System.Drawing.Size(390, 148);
    	this.tbVPConditions.TabIndex = 1;
    	this.tbVPConditions.Text = "";
    	this.tbVPConditions.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbVPConditions_KeyPress);
    	// 
    	// toolStrip1
    	// 
    	toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
    	toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    	this.btnWizard,
    	this.btnLibrary,
    	this.btnClear});
    	toolStrip1.Location = new System.Drawing.Point(0, 0);
    	toolStrip1.Name = "toolStrip1";
    	toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
    	toolStrip1.Size = new System.Drawing.Size(390, 25);
    	toolStrip1.TabIndex = 0;
    	toolStrip1.Text = "toolStrip1";
    	// 
    	// btnWizard
    	// 
    	this.btnWizard.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
    	this.btnWizard.ImageTransparentColor = System.Drawing.Color.Magenta;
    	this.btnWizard.Name = "btnWizard";
    	this.btnWizard.Size = new System.Drawing.Size(23, 22);
    	this.btnWizard.Tag = "BTNWIZARD";
    	this.btnWizard.Click += new System.EventHandler(this.btnWizard_Click);
    	// 
    	// btnLibrary
    	// 
    	this.btnLibrary.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
    	this.btnLibrary.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
    	this.tsSaveQuery,
    	this.tsUseQuery});
    	this.btnLibrary.ImageTransparentColor = System.Drawing.Color.Magenta;
    	this.btnLibrary.Name = "btnLibrary";
    	this.btnLibrary.Size = new System.Drawing.Size(13, 22);
    	this.btnLibrary.Tag = "BTNLIBRARY";
    	// 
    	// tsSaveQuery
    	// 
    	this.tsSaveQuery.Name = "tsSaveQuery";
    	this.tsSaveQuery.Size = new System.Drawing.Size(78, 22);
    	this.tsSaveQuery.Tag = "BTNLIBRARYSAVE";
    	this.tsSaveQuery.Click += new System.EventHandler(this.tsSaveQuery_Click);
    	// 
    	// tsUseQuery
    	// 
    	this.tsUseQuery.Name = "tsUseQuery";
    	this.tsUseQuery.Size = new System.Drawing.Size(78, 22);
    	this.tsUseQuery.Tag = "BTNLIBRARYUSE";
    	this.tsUseQuery.Click += new System.EventHandler(this.tsUseQuery_Click);
    	// 
    	// btnClear
    	// 
    	this.btnClear.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
    	this.btnClear.ImageTransparentColor = System.Drawing.Color.Magenta;
    	this.btnClear.Name = "btnClear";
    	this.btnClear.Size = new System.Drawing.Size(23, 22);
    	this.btnClear.Tag = "BTNCLEAR";
    	this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
    	// 
    	// panel2
    	// 
    	panel2.Controls.Add(this.textBox1);
    	panel2.Controls.Add(this.labelConditions);
    	panel2.Controls.Add(this.labelType);
    	panel2.Controls.Add(this.labelAction);
    	panel2.Controls.Add(this.label2);
    	panel2.Controls.Add(this.label1);
    	panel2.Controls.Add(this.cbVPField);
    	panel2.Controls.Add(this.cbVPType);
    	panel2.Controls.Add(this.cbVPAction);
    	panel2.Dock = System.Windows.Forms.DockStyle.Top;
    	panel2.Location = new System.Drawing.Point(0, 0);
    	panel2.Name = "panel2";
    	panel2.Size = new System.Drawing.Size(390, 197);
    	panel2.TabIndex = 1;
    	// 
    	// textBox1
    	// 
    	this.textBox1.Location = new System.Drawing.Point(12, 70);
    	this.textBox1.Name = "textBox1";
    	this.textBox1.Size = new System.Drawing.Size(245, 20);
    	this.textBox1.TabIndex = 10;
    	// 
    	// labelConditions
    	// 
    	this.labelConditions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    	this.labelConditions.Location = new System.Drawing.Point(12, 178);
    	this.labelConditions.Name = "labelConditions";
    	this.labelConditions.Size = new System.Drawing.Size(366, 13);
    	this.labelConditions.TabIndex = 9;
    	this.labelConditions.Text = "Specify how to identify the data:";
    	this.labelConditions.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    	// 
    	// labelType
    	// 
    	this.labelType.Location = new System.Drawing.Point(12, 136);
    	this.labelType.Name = "labelType";
    	this.labelType.Size = new System.Drawing.Size(245, 13);
    	this.labelType.TabIndex = 8;
    	this.labelType.Tag = "VPFIELD.TYPE";
    	this.labelType.Text = "Format:";
    	this.labelType.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
    	// 
    	// labelAction
    	// 
    	this.labelAction.Location = new System.Drawing.Point(12, 94);
    	this.labelAction.Name = "labelAction";
    	this.labelAction.Size = new System.Drawing.Size(245, 13);
    	this.labelAction.TabIndex = 7;
    	this.labelAction.Tag = "VPFIELD.ACTION";
    	this.labelAction.Text = "Action:";
    	this.labelAction.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    	// 
    	// label2
    	// 
    	this.label2.AutoSize = true;
    	this.label2.Location = new System.Drawing.Point(12, 53);
    	this.label2.Name = "label2";
    	this.label2.Size = new System.Drawing.Size(38, 13);
    	this.label2.TabIndex = 5;
    	this.label2.Text = "Name:";
    	this.label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
    	// 
    	// label1
    	// 
    	this.label1.AutoSize = true;
    	this.label1.Location = new System.Drawing.Point(12, 11);
    	this.label1.Name = "label1";
    	this.label1.Size = new System.Drawing.Size(195, 13);
    	this.label1.TabIndex = 4;
    	this.label1.Text = "Select what VP data shall be accessed:";
    	this.label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
    	// 
    	// cbVPField
    	// 
    	this.cbVPField.DisplayMember = "Display";
    	this.cbVPField.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    	this.cbVPField.FormattingEnabled = true;
    	this.cbVPField.Location = new System.Drawing.Point(12, 28);
    	this.cbVPField.Margin = new System.Windows.Forms.Padding(3, 3, 6, 3);
    	this.cbVPField.Name = "cbVPField";
    	this.cbVPField.Size = new System.Drawing.Size(245, 21);
    	this.cbVPField.Sorted = true;
    	this.cbVPField.TabIndex = 0;
    	this.cbVPField.ValueMember = "Index";
    	this.cbVPField.SelectedValueChanged += new System.EventHandler(this.cbVPField_SelectedValueChanged);
    	// 
    	// cbVPType
    	// 
    	this.cbVPType.DisplayMember = "Display";
    	this.cbVPType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    	this.cbVPType.FormattingEnabled = true;
    	this.cbVPType.Location = new System.Drawing.Point(12, 153);
    	this.cbVPType.Name = "cbVPType";
    	this.cbVPType.Size = new System.Drawing.Size(147, 21);
    	this.cbVPType.TabIndex = 1;
    	this.cbVPType.ValueMember = "Index";
    	// 
    	// cbVPAction
    	// 
    	this.cbVPAction.DisplayMember = "Display";
    	this.cbVPAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    	this.cbVPAction.FormattingEnabled = true;
    	this.cbVPAction.Location = new System.Drawing.Point(12, 111);
    	this.cbVPAction.Name = "cbVPAction";
    	this.cbVPAction.Size = new System.Drawing.Size(147, 21);
    	this.cbVPAction.TabIndex = 0;
    	this.cbVPAction.ValueMember = "Index";
    	// 
    	// groupBox1
    	// 
    	this.groupBox1.Controls.Add(this.btnCancel);
    	this.groupBox1.Controls.Add(this.btnOK);
    	this.groupBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
    	this.groupBox1.Location = new System.Drawing.Point(2, 372);
    	this.groupBox1.Name = "groupBox1";
    	this.groupBox1.Size = new System.Drawing.Size(390, 38);
    	this.groupBox1.TabIndex = 1;
    	this.groupBox1.TabStop = false;
    	// 
    	// btnCancel
    	// 
    	this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    	this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    	this.btnCancel.Location = new System.Drawing.Point(256, 10);
    	this.btnCancel.Name = "btnCancel";
    	this.btnCancel.Size = new System.Drawing.Size(75, 23);
    	this.btnCancel.TabIndex = 1;
    	this.btnCancel.Tag = "BTNCANCEL";
    	this.btnCancel.UseVisualStyleBackColor = true;
    	this.btnCancel.Click += new System.EventHandler(this.btn_Click);
    	// 
    	// btnOK
    	// 
    	this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    	this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
    	this.btnOK.Location = new System.Drawing.Point(60, 10);
    	this.btnOK.Name = "btnOK";
    	this.btnOK.Size = new System.Drawing.Size(75, 23);
    	this.btnOK.TabIndex = 0;
    	this.btnOK.Tag = "BTNOK";
    	this.btnOK.UseVisualStyleBackColor = true;
    	this.btnOK.Click += new System.EventHandler(this.btn_Click);
    	// 
    	// VPFieldCellPropertyDesigner
    	// 
    	this.AcceptButton = this.btnOK;
    	this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    	this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    	this.CancelButton = this.btnCancel;
    	this.ClientSize = new System.Drawing.Size(394, 412);
    	this.Controls.Add(panel1);
    	this.Controls.Add(this.groupBox1);
    	this.MinimumSize = new System.Drawing.Size(350, 300);
    	this.Name = "VPFieldCellPropertyDesigner";
    	this.Padding = new System.Windows.Forms.Padding(2);
    	this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
    	this.Tag = "VPFIELD.TEXT";
    	this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VPFieldCellPropertyDesigner_FormClosing);
    	panel1.ResumeLayout(false);
    	panel3.ResumeLayout(false);
    	panel3.PerformLayout();
    	toolStrip1.ResumeLayout(false);
    	toolStrip1.PerformLayout();
    	panel2.ResumeLayout(false);
    	panel2.PerformLayout();
    	this.groupBox1.ResumeLayout(false);
    	this.ResumeLayout(false);
    }

    But this is not the only designer that cause this problem. I've noticed that if i build, close the VS and open it again i can see the form in IDE.

    Wednesday, April 7, 2010 12:31 PM
  • The code is fine, but you forgot to mention which control you are talking about. :)
    The control you are talking about is not initialized. Maybe its not being set in the InitializeComponents at all?!!

    Nothing can be said as of now. Please provide the name of control variable.

    Thursday, April 15, 2010 10:10 AM
  • But i said.

    Is a new textbox control. The control is named tbVPConditions

    Thursday, April 15, 2010 11:12 AM
  • I just ran into this same thing.  I did Build->Rebuild Solution.  Close Visual Studio, re-open.  It seems to have worked. 

    I think I got it into that state because my user control threw an exception during design time construction.  It only cleared up after Visual Studio restart.  (Visual Studio 2008 w/SP1)

     

     


    Marshall Belew
    • Edited by mbelew Friday, October 29, 2010 3:34 PM sig was in there twice
    Friday, October 29, 2010 3:32 PM
  • I'm having the same problem:

        private void InitializeComponent()
        {
          System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChannelSetViewWnd));
          this.chnlSetViewControl = new Zylaphon.ChannelSetViewControl();
          this.chbViewLock = new System.Windows.Forms.CheckBox();
          this.btnReFormat = new System.Windows.Forms.Button();
          this.btnShowInfoWnd = new System.Windows.Forms.Button();
          this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
          this.SuspendLayout();
          // 
    // ...
    // later in this same InitializeComponent() method
    
          this.Controls.Add(this.btnShowInfoWnd);
          this.Controls.Add(this.btnReFormat);
          this.Controls.Add(this.chbViewLock);
          this.Controls.Add(this.chnlSetViewControl);
          this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
          this.KeyPreview = false;
    // ...
    }
    

    the error occurs when I attempt to open the designer and the error states that the problem is on this line: < this.Controls.Add(this.chnlSetViewControl); > The solution builds and executes w/o problems as does the form which calls the above method.

    Grateful for any help,

    robert1946
     

    Monday, December 27, 2010 4:33 PM
  • Uh ... Turned out the problem was due to the custom control having a problem loading a resource.  Still don't under stand how it could run without problems.
    Monday, December 27, 2010 4:51 PM
  • I just ran into this same thing.  I did Build->Rebuild Solution.  Close Visual Studio, re-open.  It seems to have worked. 

    I think I got it into that state because my user control threw an exception during design time construction.  It only cleared up after Visual Studio restart.  (Visual Studio 2008 w/SP1)

     

     


    Marshall Belew
    Thanks Marshall!
    Thursday, July 14, 2011 8:07 PM
  • Thanks.
    Wednesday, December 26, 2012 2:08 PM
  • I had the same problem. I found that the problem occurred after I changed my project to an "x86" target CPU from any CPU. When I changed it back to "any CPU" the problem went away. This option is under the Advanced Compile options in the Project Properties Compile Section.
    Saturday, April 26, 2014 9:08 AM
  • Thank you but what a crapy solution. Is there a way to notify MS of this problem ? I have VS2010 and this crap is not fixed.

    there should be a way to fix this without restarting  VS. We're not in 90's anymore.

    From a multibillion company like MS its disappointing.

    Philippe

    Thursday, May 7, 2015 3:20 PM
  • This worked... yet I have to find how to load the form with an UserControl on build set as x64

    =   =    Five years after (VS2017) and the same still occurs !!!!


    mexico

    Thursday, January 17, 2019 11:53 AM