0

Im having abit of trouble trying to figure out how to get my VB inputbox to work and then add the value entered into my multidimensional array.

The array looks like this:

int[,] toys = new int[5, 4];

and so far this is what i have for the inputbox.

 string value;
 int num;

 value = Microsoft.VisualBasic.Interaction.InputBox("Enter Number of Products", "Monday");

I need to have Monday-Friday values for 4 weeks. To do this i was thinking of using the inputbox in a for loop perhaps? Everytime the user enters input for that day it would insert it into the array?

Then repeat that for the 4 weeks?

Open to any suggestions as i am not sure the best way to go about it.

Thanks!

2
  • 1
    begin by just not using inputboxes or messageboxes in your application. they are evil programming shortcuts that cripple the user experience. Commented Jan 22, 2014 at 1:27
  • I need to mention that its required that i use that type of inputbox, my main issue is moving the values into my multidimensional array. Commented Jan 22, 2014 at 1:31

1 Answer 1

1

Using the inputbox isn't really the best way to accept inputs, as a matter of fact, it's not even good, but to satisfy your needs for now, this should be the shortest route.

VB.NET

 Dim toys(4, 3) As String
    For week As Integer = 0 To 3
        For day As Integer = 0 To 4
        toys(day, week) = InputBox("Please enter value for Day " & CStr(day + 1) & " in week " & CStr(week + 1) & ".")
    Next day
 Next week

C#

string[,] toys = new string[5, 4];
for (int week = 0; week <= 3; week++) {
    for (int day = 0; day <= 4; day++) {
        toys(day, week) = Interaction.InputBox("Please enter value for Day " + Convert.ToString(day + 1) + " in week " + Convert.ToString(week + 1) + ".");
    }
}
Sign up to request clarification or add additional context in comments.

8 Comments

Hi Chris, Thanks for the heads up. Im currently studying software development and im constantly being told the stuff im being told is the bad way of doing things. :( Also its saying toys is a variable used like a method for the c# thing
@MirroA, happy to help. Yeah it's better to avoid reserved names such as that of what you said about toys. Don't worry, this is good practice even if you're using the 'bad' ways of programming it. You get to learn stuff and that is what matters. If my post answered your question, I'd appreciate it if you mark it as answered :) Thanks.
It did, I managed to get it all working. Now the real challenge is to format the output of the array :)~
@MirroA, Alright thanks :) Do what you can for now, if you can't do it after many tries, drop me a message here and post the question :)
i tried using foreach loop but can't seem to figure it out.. i basically need to be outputting it sort of like a grid. like this; imgur.com/c0ihHyI just the week 1-4 and mon-fri style
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.