I’m making programs which will separate a two digit number from a textbox to two different labels. Later I want to take those two separate numbers and square them indiviudally and add them together. It would be great if someone can get me some help. This is what I have so far:

Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Label1.Text = "First digit:" & TextBox1.Text.Substring(0, 1)
        Label2.Text = "Second digit:" & TextBox1.Text.Substring(1, 1)

        Label3.Text = (Label1.Text) ^ 2
    End Sub
End Class

You are almost there.

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Try
        Dim val1 as Integer = Cint(TextBox1.Text.SubString(0,1))
        Dim val2 as Integer = Cint(TextBox1.Text.SubString(1,1))

        Label1.Text = "First digit:" & TextBox1.Text.Substring(0, 1)
        Label2.Text = "Second digit:" & TextBox1.Text.Substring(1, 1)

        Label3.Text = "Sum is:" & ((val1 *= val1) + (val2 *= val2))    
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

When write a code you must know what the value of variables.

Label1.Text = "First digit:" & TextBox1.Text.Substring(0, 1)
Label2.Text = "Second digit:" & TextBox1.Text.Substring(1, 1)

Label3.Text = (Label1.Text) ^ 2

Ex : TextBox1 = 12

Now Label1.Text will contain "First digit:1"
So you can't square what in label1 cause it not contain numbers but string.
As Begginnerdev suggest to put value in variables it makes you more easy to handle math operation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.