Click here to Skip to main content
15,917,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to find a way to get 2 values from a VisualBasic inputbox, and then use those values to find the certain spot in my multidimensional array and output the value to my textbox.

This is the code i have come up with.

C#
int x = 0;
int y = 0;

toys[x,y] = Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + Convert.ToString(x) + " in week " + Convert.ToString(y) + ".");

       txtOutput.Text += "Products completed on that day are: " + toys[x, y];


My issue is that the user might enter the day of the week in string format eg; "Mon" and then day would be an int.

My array looks like this.
http://i.imgur.com/QHy5SYW.jpg

If anyone could give me some ideas as to how to get this code to work it would be greatly appreciated. :)
Posted

1 solution

One way (among many) you could handle this:
C#
// in Form scope
using Microsoft.VisualBasic;

public enum WeekDay
{
    Monday, Tuesday, Wednesday, Thursday, Friday
}

public enum Week
{
    One, Two, Three, Four
}
In a method:
C#
int x = 0;
int y = 0;
int result;

string intCandidate = Interaction.InputBox("Please enter value for Day " + ((WeekDay)x).ToString() + " in Week " + ((Week)y).ToString());

if(Int32.TryParse(intCandidate, out result))
{
    toys[x, y] = result;
}
else
{
    // handle error input
    throw new ArgumentException("You must input an integer.");
}
Consider whether you should also check the x,y variables to make sure they are in the proper range.

Why did I use Enums rather than just List<string>: just because I felt like doing it a slightly different way.

I wonder why you needed to use Visual Basic here; why not just use two NumericUpDown Controls in C# ?
 
Share this answer
 
v2

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