Dialogresult scope problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm new to C# & just experimenting with how to use it. I can't figure out
why I can't do this.
The dialog result object is not 'seen' in the while statement of the do
loop, yet the integer is. why is this so?

The

do
{
// declare the int
int iCount = 0;
iCount++;

// declare the dialog result object
DialogResult drDoAgain;

drDoAgain = MessageBox.Show(strOP,"Do again?", MessageBoxButtons.YesNo);
}
while ( iCount < 10 && drDoagain == DialogResult.Yes);


Thanks for any help.
Ant
 
Ant,

I'm compiling on .NET 2.0 beta 2, and I get an error for both variables
being out of scope, iCount and drDoagain.

Why not just declare them outside your loop?

Hope this helps.
 
Hi Ant,

The integer should not be available either, so if you don't get a compiler error you probably have a global duplicate declared somewhere.

do/while is the same as while/(do) except the body is always executed once. The scope is the same.
 
Hi,
Thanks for your response,

I tried your idea of declaring them out of scope (before the loop) but now I
get an "Use of unsigned variable" error when I compile. I assign drResult ==
MessageBox.Show (); so it does have a return value. Hmmm. Any other ideas?

Many thanks
Ant

Nicholas Paldino said:
Ant,

I'm compiling on .NET 2.0 beta 2, and I get an error for both variables
being out of scope, iCount and drDoagain.

Why not just declare them outside your loop?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ant said:
Hi,
I'm new to C# & just experimenting with how to use it. I can't figure out
why I can't do this.
The dialog result object is not 'seen' in the while statement of the do
loop, yet the integer is. why is this so?

The

do
{
// declare the int
int iCount = 0;
iCount++;

// declare the dialog result object
DialogResult drDoAgain;

drDoAgain = MessageBox.Show(strOP,"Do again?", MessageBoxButtons.YesNo);
}
while ( iCount < 10 && drDoagain == DialogResult.Yes);


Thanks for any help.
Ant
 
Back
Top