www.webdeveloper.com
Results 1 to 6 of 6

Thread: If else problem

  1. #1
    Join Date
    May 2004
    Posts
    6

    If else problem

    I have a if else statement, like below.
    This code in a C# code.

    iFlag=0;
    if (iFlag==0)
    {
    MessageBox.Show(""+iFlag);
    iFlag=2;
    }
    else
    {
    iFlag=0;
    }

    I have kept the code in a timer_tick event
    Time is set for 500ms.

    for the first tiem of the timer tick event, both the statements in the true part is executing, but , for the second time and all only the second statement i.e iFlag=2 is only executing.,a nd MessageBox.Show is skipped.
    Even if i have any statement in that place, only the second statement is executed.
    Can anybody please help me out.
    I am mad to see this work like this.
    Sometimes,
    if i keep only 1 statement in the true and the else part, both the statements are executed.
    It is not showing me any errors, if there are some braces problem.
    please can anybody help me.

  2. #2
    Join Date
    Dec 2002
    Location
    Taiwan
    Posts
    1,297
    Looking at your code the else part should never be executed, so your code really doesn't make sense to me. Have you tried setting a breakpoint and running the debugger?

  3. #3
    Join Date
    May 2004
    Posts
    6
    if ((String.Compare(PictureBox1.BorderStyle.ToString(),"Fixed3D"))==0)
    { PictureBox1.Image=Image.FromFile("C:\\Anim\\Animation4.gif"); PictureBox1.BorderStyle=BorderStyle.None;
    }


    This is the acutal code,
    Initially while loading the form ,i am setting the borderstyle of the picturebox to fixed3d.

    And this code placed in a timer tick event,
    checks the borderstyle and changes it only if it is a fixed3d.

    For the first timee tick,
    both the statements in the if loop is executed.
    But when it comes for the second time,
    only the second statment is executed and not the first.
    Even if i change the order of the statements as,

    PictureBox1.BorderStyle=BorderStyle.None;
    PictureBox1.Image=Image.FromFile("C:\\Anim\\Animation4.gif");

    In this the second statment is only executed.
    Please help me.

  4. #4
    Join Date
    Dec 2002
    Location
    Taiwan
    Posts
    1,297
    I'll ask again, have you tried setting a breakpoint and running the debugger to see if that tells you anything?

  5. #5
    Join Date
    Jun 2004
    Posts
    4
    ur else part should never be executed.

    u just comment following line from ur code

    //iFlag=0;

    Intitalize that at declaretion portion itself


    public class .....
    {
    private int iFlag = 0;
    }

  6. #6
    Join Date
    Jul 2004
    Posts
    2
    Hmm.... it looks like it runs the same time unnoticingly for you
    if you can see, if you compare the first time if its fixed3D , then it will change the border and the image. then the second time its runs, isince the first time is the image and border, so why would it want change the image since it has already hanged in the first place?

    just a suggestion, you might want to change to another image first b4 it changes back.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles