简体   繁体   English

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

[英]What is wrong with this msgbox code? (VB)

edit: Don't worry, i made a silly mistake, I had 3 characters instead of 4 编辑:别担心,我犯了一个愚蠢的错误,我有3个字符而不是4个字符

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

So why doesn't it work? 那为什么不起作用呢? If it helps, here is the error code: 如果有帮助,这里是错误代码:

"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll “ mscorlib.dll中发生了'System.ArgumentOutOfRangeException类型的未处理的异常

Additional information: Index and length must refer to a location within the string." 附加信息:索引和长度必须引用字符串中的位置。”

我怀疑您的Label4.Text属性比您要求的短。

Can you tell me what exactly the 'Label4' contains, I know it has numbers, but what other text. 您能告诉我'Label4'到底包含什么,我知道它有数字,但还有其他文字。 Sorry for doing this as an answer but the 'Comment' button isn't anywhere on the page. 很抱歉将其作为答案,但是“注释”按钮不在页面上的任何位置。

I realize you have already accepted an answer but I am responding to your comment that you want it to display in seconds. 我知道您已经接受了答案,但是我正在答复您希望它在几秒钟内显示的评论。 Try something like this: 尝试这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM