Question

I'm writing an application that will search a flat file for specific data based on user input, and it's coming along. But, I must be an idiot. I've checked through this method three times and am not seeing a path where a value isn't returned, yet VS 2010 Express assures me there is one.

What the hell am I missing? Thanks in advance.

private string UserData(string[] userDB, bool forEnrollment){

    if (nameButton.Checked)
    {
        if (personBox.Text.Split(' ').Length != 2)
        {
            WriteDebug("ERROR: Invalid user input");
            return null;
        }
        else
        {
            List<string> namesFound = new List<string>(); //list of matches for the current person                


            string parsedFirst = personBox.Text.Split(' ')[0];
            string parsedLast = personBox.Text.Split(' ')[1];
            string dataSourceKey = null;

            WriteDebug("Searching for '" + parsedFirst + " " + parsedLast + "'...");
            for (int d = 12; d < userDB.Length - 11; d = d + 10)  //search the flat file for matches
            {
                string dbFirst = GetThree(userDB[d]);         //first three characters of FIRST name of current record
                string dbLast = GetThree(userDB[d + 1]);      //first three characters of LAST name of current record

                if (GetThree(parsedFirst) == dbFirst && GetThree(parsedLast) == dbLast) //if the name from the list is similar to the record
                {
                    WriteDebug("Match found while comparing '" + parsedFirst + " " + parsedLast + "' to '" + userDB[d] + " " + userDB[d + 1] + "' (" + userDB[d - 1] + ")");
                    namesFound.Add(userDB[d - 1] + ": " + userDB[d] + " " + userDB[d + 1]);     //add the person to the list of matches
                    userKey = userDB[d - 1];
                    dataSourceKey = "\t" + userDB[d + 6];
                }
            }

            if (namesFound.Count == 0)  //if no matches are found, write an error line
            {
                userKey = "ERROR: No matches found for '" + parsedFirst + " " + parsedLast + "'";
                WriteDebug("ERROR: No matches found for '" + parsedLast + " " + parsedLast + "'");
                return "[ERROR]";
            }
            else if (namesFound.Count == 1) //if a single match is found, add the record
            {
                if (forEnrollment) {
                    return userKey;
                }
                return userKey + dataSourceKey;
            }
            else
            {
                WriteDebug("ERROR: Multiple matches found for '" + parsedFirst + " " + parsedLast + "'");
                /*TODO 
                    *   add instance of ConflictBox and populate it with namesFound
                    *   prompt user to select one of the matches or skip the record entirely
                    */
                return "[ERROR]";
            }

        }
    }
    else
    {
        /*TODO
         *  search for the student id
         * 
         */
        return "[UNFINISHED CODE]";
    }
}
Was it helpful?

Solution

Appears to have been a glitch with VS 2010; closing and reopening the project fixed it. At least I know it wasn't my own error!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top