如何从消息框中读取输入?

时间:2013-11-07 21:55:27

标签: vb.net

Microsoft.VisualBasic.Interaction.InputBox(“提供ID变异”,“变异”,“输入您的ID”);

我能够阅读输入,但是如何?

此外,是否有可能如果我按下1之类的数字,我将获得以下所有信息?

Mp3Player player1 = new Mp3Player(1, "GET Technologies .inc", "HF 410", 4096, 129.95M, 500);

1 个答案:

答案 0 :(得分:1)

您可以指定结果:

string id = Microsoft.VisualBasic.Interaction.InputBox("Give an ID to mutate", "Mutation", "Enter your ID");

如果您尝试将此转换为数字,则需要将字符串转换为数字:

string idString = Microsoft.VisualBasic.Interaction.InputBox("Give an ID to mutate", "Mutation", "Enter your ID");

int id;
if (int.TryParse(idString, out id))
{
    Mp3Player player = new Mp3Player(id, "GET Technologies .inc", "HF 410", 4096, 129.95M, 500);
}
else
{
     // The user typed something that wasn't a number
}