My first post ever anywhere! :)
As a novice I may be asking a stupid question here. Although arraysize exists, postcode array doesn't when I try to work with it in the addToArray method (and yes I know there are some other issues but I'll sort those later):
namespace Postcodes
{
public partial class _Default : System.Web.UI.Page
{
string[] PostcodeArray = new string[] { " " };
int ArraySize = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
ltrListofCodes.Text = "Codes you enter will appear here";
}
protected void btnAddCode_Click(object sender, EventArgs e)
{
string postCodeRegEx =
@"(^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$)|(^
*$)";
//Validate the postcode and if its good then add it to the optimisation problem
if (System.Text.RegularExpressions.Regex.IsMatch(txtPostcode.Text, postCodeRegEx) ==
false)
ltrListofCodes.Text = "Bad postcode:" + " " + txtPostcode.Text;
else
addToArray(txtPostcode.Text);
}
protected void addToArray(string nextPostcode)
{
// Build the string array of valid postcodes
PostcodeArray(ArraySize) = nextPostcode;
ArraySize++;
;
}
protected void btnOptimise_Click(object sender, EventArgs e)
{
Response.Redirect("Results.aspx");
}
}
}