Solved

Problem setting editbox value.

Posted on 2002-04-15
3
173 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 68
abstract class with all non abstract mentods 6 76
How to convert MFC::CString to UTF8 wchar_t* 10 148
Message not shown 5 33
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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