Wow, you couldn't ask for a better opportunity to show off.
I asked them to give me an hour with an Internet connection, and here's what I came up with (code is in C#.NET):
static void Main(string[] args)
{
Excel.Application excel = new Excel.Application();
excel.Visible = true;
Workbook excelWorkbook =
excel.Workbooks.Open("store.xls",
0, false, 5, "", "", false,
Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
Worksheet frontSheet =
(Worksheet)excelWorkbook.Sheets.get_Item("Sheet1");
for (int i = 2; i < 4124; i++)
{
try
{
Range zip = frontSheet.get_Range(("J" + i.ToString()),
Type.Missing);
string builder = "http://ws.fraudlabs.com/ZIPCodeWorldUS_WebService.asmx/ZIPCodeWorld_US?";
builder += "ZIPCODE=" + zip.Text.ToString().Trim();
builder += "&LICENSE=05-Y34L-X86F";
WebClient web_client = new WebClient();
byte[] x_response =
web_client.DownloadData(builder.ToString());
string response = Encoding.Default.GetString(x_response);
string strParam = ""; ");
int indexOpen = response.IndexOf(strParam) + strParam.Length;
int indexClose = response.IndexOf("
string countyName = response.Substring(indexOpen, indexClose - indexOpen);
Range county = frontSheet.get_Range(("I" + i.ToString()),
Type.Missing);
county.Value2 = countyName;
Thread.Sleep(500);
}
catch (Exception e)
{
Console.WriteLine("" + i.ToString() + ": " + e.Message);
}
}
}
No big thing. It's about 60 lines of code, and for some reason it's one of the most satisfying things I've ever written. Notice the following things about the code: -
-It's not well abstracted
-I did not package it into a library for reuse
-There are many hard-coded values
-file paths are hard-coded relative paths
-it's not particularly efficient (I could have cached repeated results, for example, and applied them without making the webservice call).
-it doesn't follow good naming conventions.
-the exception handling is minimal
-it is not "flexible" by any definition of the word.
Each one of the above points is in direct violation of the all the software principals that I am a very strong advocate of. But the fact of the matter is that this little chunk of code turned a 40 hour project for one of the client's office staff into about 15 minutes of wait time. It took a need, and provided a solution, as quickly as possible.
I think it's possible to get lost in the ideals of "good" software. Believe me, I'm all for sound architecture and the Best-Practices. But honestly, the best measure of any piece of software is how much it helps the person who is using it, and sometimes what you really need is a script.
