CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2009
    Posts
    3

    Variable not changing

    I am working on a assignment for uni using vs05 clr form project.
    I got have been working on it for a while and it was all working then i got to a point that if i instantiate a new variable it will be out of scope even the line after i assign a value to it when i break it in debug mode the line after and if i create the variable as a global it will instanciate to 0 and then even if i have a line saying loo_value2 = 5; it will still be 0.
    Here is a picture from the debug showing the value of both newly created int and a global

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Variable not changing

    Post code, not screen shots.

  3. #3
    Join Date
    May 2009
    Posts
    3

    Re: Variable not changing

    How much should i post because my forms header file is just under 1000 lines long

    this is the first little bit of the for loop where it first starts occuring
    i break it at the if statement and that is where i know that it is the loop_value2 was not changing so i then added the int tester to see it and it says that its out of scope
    Code:
     
    for(loop_value = player_X; loop_value <= xval; loop_value = loop_value + ad_minus)
    {
           loop_value2 = loop_value - player_X;
           loop_value2 = 5;
    
           int tester = 10;
           if(loop_value > 13 || loop_value < 0)
           {
                  g->DrawImage(black, (int)(loop_value2 * 56.5), (int)(loop_value2 * 56.5), 565- loop_value2 * 113, 565 - loop_value2 * 113);
                  label6->Text = ""  + loop_value2 * 113;
                  label7->Text = ""  + loop_value2 * 113;
                  g->DrawImage(black, 0, 0, 5, 5);
                  break;
            }
    The for loop is in a else if and i looked at the next else if and found that i had declared it again as soon as i removed the int decleration it worked in this for loop though i am still getting the new int tester is out of scope.
    Last edited by anon_boy; May 9th, 2009 at 12:26 PM. Reason: adding info

  4. #4
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: Variable not changing

    Quote Originally Posted by anon_boy View Post
    How much should i post because my forms header file is just under 1000 lines long

    this is the first little bit of the for loop where it first starts occuring
    i break it at the if statement and that is where i know that it is the loop_value2 was not changing so i then added the int tester to see it and it says that its out of scope
    Code:
     
    for(loop_value = player_X; loop_value <= xval; loop_value = loop_value + ad_minus)
    {
           loop_value2 = loop_value - player_X;
           loop_value2 = 5;
    
           int tester = 10;
           if(loop_value > 13 || loop_value < 0)
           {
                  g->DrawImage(black, (int)(loop_value2 * 56.5), (int)(loop_value2 * 56.5), 565- loop_value2 * 113, 565 - loop_value2 * 113);
                  label6->Text = ""  + loop_value2 * 113;
                  label7->Text = ""  + loop_value2 * 113;
                  g->DrawImage(black, 0, 0, 5, 5);
                  break;
            }
    The for loop is in a else if and i looked at the next else if and found that i had declared it again as soon as i removed the int decleration it worked in this for loop though i am still getting the new int tester is out of scope.
    You do realize that you are declaring "tester" in a loop ???
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Variable not changing

    Quote Originally Posted by anon_boy View Post
    I am working on a assignment for uni using vs05 clr form project.
    You are not in the correct forum. This forum is for non-managed Visual C++ coding. You want the Managed C++ forum.

    Regards,

    Paul McKenzie

  6. #6
    Join Date
    May 2009
    Posts
    3

    Re: Variable not changing

    Oh ok sorry I wasn't sure because one of my lecturers has been referring to this as visual c++, i know that it was managed but because of what the lecturer has been saying I wasn't sure which one it went in i will go over to that forum now.

    thank you

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured