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

时间:2013-04-10 11:41:15

标签: 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

代码二

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

代码三

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

7 个答案:

答案 0 :(得分: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

更优雅的方式:

        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

答案 1 :(得分:3)

不是最优雅的解决方案,但有效:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim vote As Integer
    If showcountwinnie.Text <> "" Then
        vote = Val(showcountwinnie.Text)
    Else
        vote = 0
    End If

    vote += 1
    showcountwinnie.Text = vote
End Sub

答案 2 :(得分:1)

使用上面建议的代码,我发布的代码对我来说真的很有用,只需稍作修改

scala> import spray.json._
import spray.json._

scala> import scala.concurrent.Future
import scala.concurrent.Future

scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global

scala> val f1 = Future(JsArray(JsNumber(1), JsNumber(2))) 
f1: scala.concurrent.Future[spray.json.JsArray] = List()

scala> val f2 = Future(JsArray(JsNumber(3), JsNumber(4), JsNumber(5)))
f2: scala.concurrent.Future[spray.json.JsArray] = List()

scala> map2(f1, f2)(merge).onComplete(println)
Success([1,2,3,4,5])

答案 3 :(得分:0)

守则1似乎是正确的。只需尝试在第1行保留断点,并在单击按钮

时检查代码行是否正在执行

答案 4 :(得分:0)

试试这个

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Static votecount As Integer = 0
    votecount += 1
    showcountwinnie.Text = votecount.ToString()
End Sub

答案 5 :(得分:0)

showcountwinnie.Text = showcountwinnie.text + 1

此方法用于每次点击+1

答案 6 :(得分:-1)

有点晚但你的代码1不会工作Parse方法需要两个参数。
在代码二中,你的意思是从诸如 showcountwinnie.Text = votes 之类的东西中反过来分配东西。这究竟是什么showcountwinnie?一个文本框?标签?