您好我正在使用microsoft visual studio 2010版本,我需要在其上制作一个if语句。
我正在做的是将一个数字放入文本框,然后进入我的列表框(不过我多次将数字放入3-4个数字)。然后它意味着将它们全部添加并在之后将其放入标签中。
到目前为止,这是该计划的目标
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Result As Integer
For Each Item As Integer In ListBox1.Items
Result = Result + Item
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Value As String
Value = TextBox1.Text
ListBox1.Items.Add(Value)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Label1.Text = "You have a Balance of " + DialogResult.ToString
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If (String.a
End Sub
End Class
答案 0 :(得分:0)
在Visual Basic .NET中(您的代码看起来就是这样),If
语句的格式如下:
If condition Then
DoSomeCodeHere()
End If
C#代码格式为
if (condition)
{
DoSomeCodeHere();
}
答案 1 :(得分:0)
你的意思是你把列表框中的所有金额都计算在一起,并在点击按钮2后将其显示在标签中? 如果是,请添加以下内容。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Result As Integer
For Each Item As Integer In ListBox1.Items
Result = Result + Item
Next
Label1.Text = "You have a Balance of " + Result.ToString
End Sub