Solved

Problem setting editbox value.

Posted on 2002-04-15
3
168 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
  • 2
3 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now