通过一个视觉基础增加一个值我被卡住了

ben*_*ngi 1 vb.net

我正在尝试编写一个代码,在单击visual basic中的按钮后将值增加一个.这些是我到目前为止尝试过的代码但是我没有实现我的目标

代码1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim votecount As Integer = Integer.Parse(showcountwinnie.Text)
   votecount += 1
   showcountwinnie.Text = votecount.ToString()
End Sub
Run Code Online (Sandbox Code Playgroud)

代码二

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim votes As Integer
  votes = 0
  votes += 1
  votes = showcountwinnie.Text
End Sub
Run Code Online (Sandbox Code Playgroud)

代码三

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim votewinnie As Integer
   votewinnie = showcountwinnie.value
   votewinnie = votewinnie + 1
   showcountwinnie.value = votewinnie
End Sub
Run Code Online (Sandbox Code Playgroud)

Geo*_*rge 8

快速而肮脏的方式:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            showcountwinnie.Text = (Val(showcountwinnie.Text) + 1).ToString()
        End Sub
Run Code Online (Sandbox Code Playgroud)

更优雅的方式:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim votecount As Integer
            If Integer.TryParse(txt_UTC.Text, votecount) Then
                votecount += 1
            Else
                ' whatever you want to do with votecount
                votecount = 0
            End If
            txt_UTC.Text = votecount.ToString()
        End Sub
Run Code Online (Sandbox Code Playgroud)