473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

use of unassigned local varible 'form2'

Expand|Select|Wrap|Line Numbers
  1. private void toolStripButton1_Click(object sender, EventArgs e)
  2.         {
  3.             Form2 form2;
  4.             if (form2 == null || form2.IsDisposed)
  5.             {
  6.                 form2 = new Form2();
  7.                 form2.MdiParent = this;
  8.                 form2.Show();
  9.             }
  10.             else
  11.             {
  12.                 form2.Activate();
  13.             }
  14.         }
Nov 7 '10 #1
2 1716
GaryTexmo
1,501 Expert 1GB
I think it's complaining because you're defining form2, then checking if it will equal null.

In your case, form2 will never not be null. Either make form2 a class member or a parameter of some kind.
Nov 7 '10 #2
Thanks!
I'll try it.
Nov 8 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike P | last post by:
I keep getting the error 'Use of unassigned local variable' in my code, which I have used before and it works fine : SqlTransaction Trans1, Trans2; SqlConnection...
5
by: Mike P | last post by:
I am instantiating a class in a switch statement as there are a number of different overloads depending upon the data entered by the user. The problem I have is that after instantiating my class,...
3
by: John Smith | last post by:
In the following (pseudo)code, why is it that C# returns an "unassigned local variable" error for nVar? It seems I have to declare the variable outside foo() for the error to dissapear. void...
2
by: Doug | last post by:
I am trying to work with an object and create it like so: EXTRA.Sessions oSessions = new EXTRA.Sessions(); This doesn't work because I get this error: 'Cannot create an instance of the...
9
by: tshad | last post by:
I am getting an error: Use of unassigned local variable 'postDateRow' But it is assigned. Here is the code: int payDateRow; int postDateRow;
22
by: Laura T. | last post by:
In the following example, c# 2.0 compiler says that a3 and ret are used before assigned. as far as I can see, definite assignment is made. If I add finally { ret = true; a3 = "b3";
3
by: Hegel | last post by:
Some body please help me. I finds this code really correct. However I am a beginner The following code yields Use of unassigned local variable 'fout' error in my pgm please help using...
2
by: plasmay | last post by:
Hi, I am new in learning c#, and have recently encountered a problem: static float ComputeAvg(float a) { float sum; int i; for (i = 0; i...
3
by: lenniekuah | last post by:
Hi Good Guy, I am very surprised of the coding generate error message Error 1 Use of unassigned local variable 'strSql' even though the strSQL variable was declared. Not sure what is wrong...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.