Int32 error

  • Thread starter Thread starter Tu-Thach
  • Start date Start date
T

Tu-Thach

Ron,
What are you trying to do? Read from a database? This
error indicates that you are trying to read an int, but
the value is outside the range of an integer: -
2,147,483,648 through 2,147,483,647.

Tu-Thach
 
It is happening in the the following methode i have.
The only thing i can think of is that it is happening
during one of the Parse routine's.
How can i define the trap to be better?
It dose not happen all the time just once in a while.

Thanks Ron

protected void GetJudgements()
{
int j = 0;
try
{
// Check test position's 1-5 judgement.
for(int i=4; i<84; i+=20)
{
judgements[j] = int.Parse(dmArray);
j++;
}

// Check on-line status of test positions 6 and 7
// preform judgement logic accordingly.
if((TestOnline[5]) & (TestOnline[6]))
{
// Check test position 6 judgement.
judgements[5] = (0x0 != int.Parse(dmArray[113],
NumberStyles.HexNumber))? 1 : 0;
// Look at tracking and test flags for no-test condition.
judgements[5] = (dmArray[121].Substring(5,1) == "1" &
dmArray[122].Substring(5,1) == "0")? 2 : 0;

// Check test position 7 judgement
// Look at tracking and test flags for no-test condition.
if(dmArray[121].Substring(6,1) == "1" & dmArray
[122].Substring(6,1) == "0")
{
judgements[6] = 2;
}
else
{
judgements[6] = int.Parse(dmArray[104]);
}
}
else if((TestOnline[5] == true) & (TestOnline[6] ==
false))
{
judgements[5] = int.Parse(dmArray[104]);
}
else if((TestOnline[5] == false) & (TestOnline[6] ==
true))
{
judgements[6] = int.Parse(dmArray[104]);
}
}
catch(Exception e)
{
string errorMessage = "";

errorMessage = "Message: " + e.Message + "\n";

EventLog log = new EventLog();
log.Source = "DataCollectionServer";
log.WriteEntry(errorMessage);
}
}
 
Tu-Thach,
You are correct i found the value in dmArray[113]
was "1000000000000110" which is equal to 32774.
So i decided to change that line to the following.

judgements[5] = (0 != Convert.ToInt32(dmArray[113], 2))?
1 : 0;

The value in dmArray[113] has the possability to hold the
following "1111111111111111" to "0000000000000000".

This should solve my problem i am only checking that
value to see if it is not equal to zero.

Thanks Ron
-----Original Message-----
Ron,
I think the data in dmArray that you are trying to parse
might be larger than the range of integer value.

Tu-Thach
-----Original Message-----
It is happening in the the following methode i have.
The only thing i can think of is that it is happening
during one of the Parse routine's.
How can i define the trap to be better?
It dose not happen all the time just once in a while.

Thanks Ron

protected void GetJudgements()
{
int j = 0;
try
{
// Check test position's 1-5 judgement.
for(int i=4; i<84; i+=20)
{
judgements[j] = int.Parse(dmArray);
j++;
}

// Check on-line status of test positions 6 and 7
// preform judgement logic accordingly.
if((TestOnline[5]) & (TestOnline[6]))
{
// Check test position 6 judgement.
judgements[5] = (0x0 != int.Parse(dmArray[113],
NumberStyles.HexNumber))? 1 : 0;
// Look at tracking and test flags for no-test condition.
judgements[5] = (dmArray[121].Substring(5,1) == "1" &
dmArray[122].Substring(5,1) == "0")? 2 : 0;

// Check test position 7 judgement
// Look at tracking and test flags for no-test condition.
if(dmArray[121].Substring(6,1) == "1" & dmArray
[122].Substring(6,1) == "0")
{
judgements[6] = 2;
}
else
{
judgements[6] = int.Parse(dmArray[104]);
}
}
else if((TestOnline[5] == true) & (TestOnline[6] ==
false))
{
judgements[5] = int.Parse(dmArray[104]);
}
else if((TestOnline[5] == false) & (TestOnline[6] ==
true))
{
judgements[6] = int.Parse(dmArray[104]);
}
}
catch(Exception e)
{
string errorMessage = "";

errorMessage = "Message: " + e.Message + "\n";

EventLog log = new EventLog();
log.Source = "DataCollectionServer";
log.WriteEntry(errorMessage);
}
}



-----Original Message-----
Ron,
What are you trying to do? Read from a database? This
error indicates that you are trying to read an int, but
the value is outside the range of an integer: -
2,147,483,648 through 2,147,483,647.

Tu-Thach

-----Original Message-----
Hi,
I am trying to find the meaing to the following error.
"Value was either too large or too small for an Int32."

Can someone give me some more information on this error?

Thanks Ron
.

.
.

.
 
Back
Top