Solved

Problem setting editbox value.

Posted on 2002-04-15
3
190 Views
Last Modified: 2013-11-20
Hi,

I have the following code:

ShowWindow(SW_RESTORE);

CString temper ="";

int m_High1 = m_Highscore1;
int m_High2 = m_Highscore2;
int m_High3 = m_Highscore3;
int m_High4 = m_Highscore4;
int m_High5 = m_Highscore5;

temper.Format("%d1 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High5){
temper.Format("%d2 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High4){
temper.Format("%d3 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High3){
temper.Format("%d4 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High2){
temper.Format("%d5 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High1){
temper.Format("%d6 ",iScorecpy);
MessageBox(temper);

}else{}

}else{m_High2=iScorecpy;
temper.Format("%d7 ",iScorecpy);
MessageBox(temper);
}
}else{m_High3=iScorecpy;
temper.Format("%d8 ",iScorecpy);
MessageBox(temper);
}
}else{m_High4=iScorecpy;
temper.Format("%d9 ",iScorecpy);
MessageBox(temper);
}
}else{m_High5=iScorecpy;
temper.Format("%d10 ",iScorecpy);
MessageBox(temper);
}
SaveStuff();

//Shows desktop
::ShowWindow (hProgMan, SW_SHOW);

this->SetFocus();

UpdateData(FALSE);

I've put the messagebox's in there so that I can make sure that a value is being set for iScorecopy.

m_Highscore1 - 5 are integars of five edit box controls which I display on my dialog. iScorecopy gets set a value from the previous dialog and is fine up to the point where I do:

if(iScorecpy>m_High1){
temper.Format("%d6 ",iScorecpy);
MessageBox(temper);

For some reason iScorecpy get's the value which is already contained in the editbox? It doesn't use m_iHigh as a condition but sets iScorecpy to that value?!
Then all values (iScorecpy) below temper.Format("%d7 ",iScorecpy); are 0.

I hope I have explained this well, and hope someone can help.

Thanks in advance.
0
Comment
Question by:ukking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6943022
Wow, your code is way too complicated!  I'm not sure what all of those if/else pairs are designed to do, but the lines like this:

if(iScorecpy>m_High5){
     temper.Format("%d2 ",iScorecpy);
     MessageBox(temper);

     if(iScorecpy>m_High4){
          temper.Format("%d3 ",iScorecpy);
          MessageBox(temper);
          (...etc...)
are meaningless because ALL of the ifs below the first one will ALWYAS be FALSE.  In otherwords, none of that code will be executed.  The only code that will EVER be executed is:

temper.Format("%d1 ",iScorecpy);
MessageBox(temper);

if(iScorecpy>m_High5){
     temper.Format("%d2 ",iScorecpy);
     MessageBox(temper);
}
else {
     m_High5=iScorecpy;
     temper.Format("%d10 ",iScorecpy);
     MessageBox(temper);
}
SaveStuff();

=-=-=-=-=-=-=-=-=-=-
If you explain what you are trying to do (that is, what is the purpose of the code), I'll help you code it up.

-- Dan
0
 

Author Comment

by:ukking
ID: 6944362
But why do the messageboxes display?

Here's the scenario:

I have a dialog which I execute from a function, this dialog is a game and a score gets returned to the above function (iScorecpy).

Within the dialog in the above class I have five editboxes
(five highest scores) but only the highest score ever gets set (m_Highscore1), but I want the others, Highscore2 to be set if lower than highscore1 and highscore3 to be set if lower than highscore2, etc.  All the way down to Highscore5.

You say that only iScorecpy>m_High5 will ever be executed, but why then does five message boxes display (the original posted explaination) happen?

My current testing involves having a highscore (m_Highscore1) and trying to fit a lower value to one of the ints below the high score but it never happens!  Only if I beat the highscore is that value changed.

Thanks for any help.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 7099547
You should put the scores into an array rather than as five separate scalar variables.  That lets you do things in a loop rather than with individual special-case statments.

Is it possible to put the high scores in an array?

-- Dan
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 84
twoTwo  challenge 35 112
Not needed 13 129
Message not shown 5 82
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question