Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Actually i am totallynew in C# 2010
so i have simple problem in IF Statement
 
So my code is
private void Timer1_Tick(object sender, EventArgs e)
{
   ProgressBar1.Value += 1;
 
   if (ProgressBar1.Value<=10)
   {
      Label1.Text = "Loading Application . . .";
   }    
   else if (ProgressBar1.Value <= 20)
   {
   }
   else if (ProgressBar1.Value <= 40)
   {
   }
   else if (ProgressBar1.Value <= 60)
   {
   }
   else if (ProgressBar1.Value <= 80)
   {
   }
  else if (ProgressBar1.Value <= 100)
  {
    Label1.Text = "Starting Application . . .";
  }
    If(ProgressBar1.Value == 100)
  {
     Timer1.Dispose();
            
    }
 }
The name 'If' does not exist in the current context error i getting
 
/Edit Pre Tag added by Jibesh
Posted 13-Jan-13 18:19pm
Edited 13-Jan-13 18:47pm
Jibesh16.5K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The error means the Keyword If is wrong you should use small if as you define above.
 
if you are using visual studio 'if' keyword will turn blue color normally. in the above case you used a capital If which is not a keyword.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Welcome to the world of C# programming. Since you are new, you should concentrate on understanding the basics and syntaxes in C# programming instead of directly jumping to programming.
 
Your lesson for today is - C# is a case-sensitive language. So a 'If' is not equal to 'if'
 
C# syntax for 'if' statement is
if(<<condition that evaluates to bool>>)
{
//Your code here
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Correct spellings of "if". its "if" and you are writing "If" see the capital "I" you placed instead of "i" in the last if
 
If(ProgressBar1.Value == 100)
 {
    Timer1.Dispose();
 
   }
 
should be
 
if(ProgressBar1.Value == 100)
 {
    Timer1.Dispose();
 
   }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Did you ever heard that C# is a case-sensitive language? This is the solution of your problem. Smile | :)
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use else at the end of all last else statement.
else
{
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

It is missing
else block .
 
you can use
else
{
}
 
before the last If statement.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,400
2 CPallini 5,240
3 George Jonsson 3,584
4 Gihan Liyanage 2,625


Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100