当我运行时,我将第一个数字分成两个标签
但是我需要从起始和结束数字之间的数字来显示
E.G 10(开始)11+12+13+14+15+16+17+18+19+20
20(结束编号)
我怎么做?
Public Class frmSumNumbers
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim sum As Integer
Dim count As Integer
Dim num1 As Integer
Dim num2 As Integer
For x = num1 To num2
sum = num1 + num2
count = count + 1
Next x
lblAnswer.Text = count
lblAnswer1.Text = sum
End Sub
End Class
答案 0 :(得分:0)
如果num1 = 1 10且num2 = 20,那么你想要一个“10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20”的文本字符串是吗?
确定你的代码应该是
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim sum As Integer
Dim count As Integer
Dim num1 As Integer
Dim num2 As Integer
Dim numberLine As String = ""
For x = num1 To num2
sum = num1 + num2
count = count + 1
numberLine = numberLine & x.ToString
If x < num2 Then
numberLine = numberLine & "+"
End If
Next x
lblAnswer.Text = count
lblAnswer1.Text = sum
lblNumberLine.Text = numberLine
End Sub