我试图弄清楚如何让我的VB输入框工作,然后将输入的值添加到我的多维数组中,我有点麻烦。
数组如下所示:
int[,] toys = new int[5, 4];
到目前为止,这就是我对输入框的所作所为。
string value;
int num;
value = Microsoft.VisualBasic.Interaction.InputBox("Enter Number of Products", "Monday");
我需要周一至周五的价值4周。 要做到这一点,我想考虑在for循环中使用输入框?每当用户输入当天的输入时,它会将其插入到数组中吗?
然后重复4周?
对任何建议持开放态度,因为我不确定最好的方法。
谢谢!
答案 0 :(得分:1)
使用输入框并不是接受输入的最佳方式,事实上,它甚至不是很好,但为了满足您现在的需求,这应该是最短路径。
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) + ".");
}
}