我试图在减去该值时让值保持在123,456,789这样的逗号顺序中。这是当前的代码:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim health As Integer
health = lblHPPlayer.Text
lblHPPlayer.Text = Val(health) - 1000
End Sub
'这就是我想要改变的价值*
lblHPPlayer.Text =" 9,850,000"
答案 0 :(得分:0)
创建名为Health
的表单级属性。你可以把它变成私人的。现在,只要您需要更新Heath
,就可以更新lblHPPlayer
中的文字。这样你就不需要解析文本了 - 它只会向你展示一个正确的整数属性的值。
这样的事情:
Private _health As Integer
Public Property Health() As Integer
Get
Return _health
End Get
Set(ByVal value As Integer)
_health = value
lblHPPlayer.Text = _health.ToString("N0")
End Set
End Property
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Health -= 1000
End Sub
答案 1 :(得分:-1)
使用数字格式说明符。
lblHPPlayer.Text = (Val(health) - 1000).toString("N0")