Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I'm working in a c# desktop application, using visual studio 2010.
I want to read each record and load a "street name dictionary" for each US state.
For example, I read first record (id=1), so I load AlabamaDictionary.txt because this record it is from Alabama State, after load it, start another process like address standardizations, etc. When this process it is finished, I read next record (id=2) and I've to check if "State" is the same, if is the same state than before, I don't need to load again AlabamaDictionary.txt because it is load it yet, start another process like address standardizations. When this process it is finished, I read next record (id=3) which is from "Arizona". Here state change so I need to load Arizona.txt and start again another address standardizations process, etc...
my problem is to change dictionary, to check when it is change.

SQL
Records
    "id" | "address"       | "state"
    1    |100 Elm St       | Alabama
    2    |300 Trawick St   | Alabama
    3    |50023 N 51st Ave | Arizona


I Have next loop
Code:
DataTable records;

C#
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string  state = records.Rows[i][2].ToString();
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
//Here I need to identify state change,
//so if state change , to use another dictionary and load it,
//but if don't change it (state), I need to use the same dictionary
//(if is load it yet)
 LoadStreetDictionary(streetDictionary);

//Process Address Standardization
StreetNameStandardization(address)
}
}



Please, How can i do this loop?
Thank you very much!
Posted

1 solution

Just create string outside the loop:
C#
string lastState = "???";
for (int i = 0; i < records.Rows.Count; i++)
    {
    string address = records.Rows[i][1].ToString();
    string  state = records.Rows[i][2].ToString();
    streetDictionary = state + ".txt";
    if(state != lastState && File.Exists(streetDictionary))
        {
        LoadStreetDictionary(streetDictionary);
        StreetNameStandardization(address)
        }
    ...
    lastState = state;
    }


[edit]first line was outside the code block :O [/edit]
 
Share this answer
 
v2
Comments
Patricio Díaz 29-May-15 10:41am    
Thanks! but dont work, because if I've first record (id=1 state=Alabama") it work fine, loading alabama.txt, but in the next record (id=2 state=Alabama") if (!state.Equals(prevSate)) dont let in, and I need to in, using same dictionary previously load it (not loading again)
OriginalGriff 29-May-15 10:57am    
You mean you need to move one line outside the "if"? :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900