O.k. I'm trying to write a program for school. the code below (I'm not posting the whole program unless you need to see it) is giving me a format exception when it hits the deptarray line?? Any ideas why??? It's reading data in from a file. It looks just like the code that was in the teacher's example?? Any help would be appreciated as I"m pulling my hair out.
static
void ParseLineIn(string lineIn, uint i){
string[] words = new string[5];lineIn = lineIn.Trim();
while (Regex.IsMatch(lineIn, "[ ] {2}"))lineIn = lineIn.Replace(
" ", " ");words = lineIn.Split(
' ');lastNameArray[i] = words[0];
firstNameArray[i] = words[1];
deptArray[i] =
UInt32.Parse(words[2]);rateArray[i] =
Double.Parse(words[3]);hoursArray[i] =
Double.Parse(words[4]);}
static void InputEmployeeData(){
uint i; string lineIn;i = 0;
while ((lineIn = fileIn.ReadLine()) != null){
i++;
ParseLineIn(lineIn, i);
}
numOfEmployees = i;
}
Jan MontanoPosted Feb 5, 2008, 3:30 AM
Assuming deptArray is declared as uint[] deptArray, format exception will occur if the current value of words[2] is not a numeric value
Amber PorterPosted Feb 4, 2008, 7:27 PM
AlanPosted Feb 4, 2008, 6:52 PM
The most likely explanation for the format exception is that the department is a string (e.g. "Sales") rather than a number.