It's not clear from your code if your accepted range is (0 - 4000000) or (-4000000 - 0), but since you are talking about Watts I assume the former. In that case, your comparisons have a logic flaw:
if((PowerData<= 0)&& (PowerData<=-4000000.000))
checks if the value is both less than zero and less than minus four million. You probably want to accept values that range from zero to four million, inclusive:
if ((PowerData >= 0) && (PowerData <= 4000000.000))
{
int IData= int(PowerData);
}
else
{
AfxMessageBox("Over Range\n!");
return;
}
You don't need to have a condition on the else, since you already know the value is out of range.