Solved

Problem setting editbox value.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

624 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