Solved

Problem setting editbox value.

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

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
Show shut-down message as Windows 8 shuts down. 9 99
dog bark java program 15 109
sum13 challenge 24 121
child constructor and parent constructor, overriding and overloading 6 88
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 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