Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have been trying for two days now to get this bit of code to work, in many different ways.
I basically need a 2d array, which asks via the visualbasic inputbox for 5days and 4 weeks worth of values (numbers) and puts them into the array.

C#
int[,] toys = new int[5, 4];
            for (int week = 0; week <= 3; week++)
            {
                for (int day = 0; day <= 4; day++)
                {
                toys[day, week] = Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + (day + 1) + " in week " + (week + 1) + ".");


I cant seem to figure out how to convert the day and week in the inputbox line to INT.
I was required to use the VB inputbox for part of my college work so have been messing around with it for quite some time and im out of ideas.

Any ideas or help would be greatly appreciated! Thanks
Posted

1 solution

You should do something like this:

C#
int tempVal = 0;
if (int.TryParse(Microsoft.VisualBasic.Interaction.InputBox("Please enter value for Day " + (day + 1) + " in week " + (week + 1) + "."), out tempVal)
{
    toys[day, week] = tempVal; 
}
else
{
    MessageBox.Show("Invalid entry");
    day--;
    continue;
}


int.TryParse() will parse the data into an integer, and it adds a check for valid data.
 
Share this answer
 
v2
Comments
Member 10540766 23-Jan-14 20:17pm    
Oh so i had to make a temp value and then do the int.parse of the whole inputbox to that?
I was trying to int.parse within the inputbox which must have been the issue.

Thank you :)

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