I have a user inputting a day (Monday) and a week number in order to search for a value in an array. However, to get the array output, I need the row and column numbers. The row number can be obtained from the user input, 1,2 etc. However, the part where they input Monday, Tuesday etc. is a bit trickier. Is there a way to convert Monday Tuesday etc to an integer (1,2) so that I can use that to find the array element?
I tried this method, but it's not working. The conversion of value to an int obviously doesn't work due to "Monday" not being a number. Is there an alternative way to doing this?
int Value = Convert.ToInt32(value);
DateTime ClockInfoFromSystem = DateTime.Now;
Value = (int)ClockInfoFromSystem.DayOfWeek;
This is the rest of the code if you need it
private void AddToArray()
{
txtOutput.Text = "Filling the array with user input..." + "\r\n\r\n";
String value;
int num;
for (int week = 0; week < productsArray.GetLength(0); week++)
{
for (int day = 0; day < productsArray.GetLength(1); day++)
{
value = Microsoft.VisualBasic.Interaction.InputBox("Enter Value for Day " + day + " of Week " + week, "Enter Value");
try
{
while (!(int.TryParse(value, out num)))
{
MessageBox.Show("Not a valid number, try again.");
value = Microsoft.VisualBasic.Interaction.InputBox("Enter a Number", "Enter Number");
}
}
catch (Exception)
{
MessageBox.Show("Value entered is not in a valid format");
}
productsArray[week, day] += int.Parse(value);
}
}
txtOutput.Text += "The product allocation is as follows:" + "\r\n\r\n";
}
private void Array()
{
txtOutput.Text += "\tMon\tTue\tWed\tThu\tFri\r\n";
for (int week = 0; week < productsArray.GetLength(0); week++)
{
txtOutput.Text += "Week " + (week + 1) + "\t";
for (int day = 0; day < productsArray.GetLength(0); day++)
{
txtOutput.Text += productsArray[week, day] + "\t";
}
txtOutput.Text += "\r\n";
}
txtOutput.Text += "\r\n" + "Retrieve products completed on a specific day." + "\r\n";
String value = Microsoft.VisualBasic.Interaction.InputBox("Enter Day", "Enter Day", "Monday");
int num;
String value2 = Microsoft.VisualBasic.Interaction.InputBox("Enter Week", "Enter Week");
try
{
while (!(int.TryParse(value2, out num)))
{
MessageBox.Show("Not a valid number, try again.");
value2 = Microsoft.VisualBasic.Interaction.InputBox("Enter Week", "Enter Week");
}
}
catch (Exception)
{
MessageBox.Show("Value entered is not in a valid format");
}
int Value2 = Convert.ToInt32(value2);
int Value = Convert.ToInt32(value);
DateTime ClockInfoFromSystem = DateTime.Now;
Value = (int)ClockInfoFromSystem.DayOfWeek;
var output = productsArray[Value2, Value];
txtOutput.Text += "Products completed on that day are: " + output;
}