“整数”类型的值无法转换为“标签”

时间:2016-10-06 15:37:09

标签: visual-studio-2015

我正在尝试从5个文本框中获取值并计算这5个框的总数,然后将它们输入到另一个框中。我相信我有一切正确,直到我尝试将这些框的值移动到最后一个框中。我收到此错误: “整数”类型的值无法转换为“标签”

程序运行正常,直到输入行。我只想弄清楚如何将计算转移到此框中。如何将“整数”转换为“标签”,或更改“标签”的格式?我进入这个VB课2周,所以这看起来像是象形文字

Public Class MainForm

'This code allows the exit button to close the application
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
    Me.Close()
End Sub
'This code allows the Calculate button to sum all boxes and enter them into the Total box.
Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click
    Dim intNum1 As Integer
    Dim intNum2 As Integer
    Dim intNum3 As Integer
    Dim intNum4 As Integer
    Dim intNum5 As Integer
    Dim intNum6 As Integer
    Dim intNum7 As Integer
    Dim intAns1 As Integer
    Dim intAns2 As Integer

    intNum1 = Val(monTextBox)
    intNum2 = Val(tuesTextBox)
    intNum3 = Val(wedTextBox)
    intNum4 = Val(thursTextBox)
    intNum5 = Val(friTextBox)
    intNum6 = Val(satTextBox)
    intNum7 = Val(sunTextBox)
    intAns1 = Val(totalWeekdayLabel)
    intAns2 = Val(totalWeekendLabel)
    intAns1 = intNum1 + intNum2 + intNum3 + intNum4 + intNum5
    totalWeekdayLabel = intAns1
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

Private Sub calcButton_Click(sender As Object, e As EventArgs) Handles calcButton.Click
    Dim intNum1 As Integer
    Dim intNum2 As Integer
    Dim intNum3 As Integer
    Dim intNum4 As Integer
    Dim intNum5 As Integer
    Dim intAns1 As Integer

    intNum1 = monTextBox.Text
    intNum2 = tuesTextBox.Text
    intNum3 = wedTextBox.Text
    intNum4 = thursTextBox.Text
    intNum5 = friTextBox.Text

    intAns1 = intNum1 + intNum2 + intNum3 + intNum4 + intNum5
    totalWeekdayLabel.Text = intAns1
End Sub

设置变量时,您需要使用TextBox.Text来获取文本值。与在标签中设置文本相同,您希望使用label.Text来设置值。

祝你班上好运<3