这个msgbox代码有什么问题? (VB)

时间:2011-12-23 20:41:09

标签: vb.net messagebox

编辑:别担心,我犯了一个愚蠢的错误,我有3个字符而不是4个

   MessageBox.Show("Well done you completed the game in " & (Label4.Text.Substring(0, 2)) & ":" & (Label4.Text.Substring(2, 2)) & " milliseconds. Well Done!")

那为什么不起作用?如果有帮助,这里是错误代码:

  

“mscorlib.dll中发生了'System.ArgumentOutOfRangeException'类型的未处理异常

     

附加信息:索引和长度必须指代字符串中的位置。“

3 个答案:

答案 0 :(得分:2)

我怀疑你的Label4.Text财产比你要求的要短。

答案 1 :(得分:1)

你能告诉我'Label4'究竟包含什么,我知道它有数字,但还有其他文字。很抱歉这样做是一个答案,但“评论”按钮不在页面的任何位置。

答案 2 :(得分:1)

我意识到你已经接受了答案,但我回复你的意见,你希望它能在几秒钟内显示出来。尝试这样的事情:

Dim result As Integer

If Integer.TryParse(Label4.text, result) Then
    MessageBox.Show("Well done you completed the game in " & (result / 1000).ToString & " seconds. Well Done!")
Else
    MessageBox.Show("Well done you completed the game in null seconds. Well Done!")
End If
相关问题