How do I go about coding the 'Calculate button' so that when a user is prompted to input a number into a Input box it will will calculate the square and square root of it?

This is what I have so far. I'm pretty sure about the first part, but am confused about the square root part.

Private Sub cmdCalc_Click()
	‘calculate square of a number
	lblTsquare.Caption=txtNumber^2
	‘calculate square root of a number
	txtNumber.Text = Sqr(txtNumber.Text)
End Sub

Recommended Answers

All 4 Replies

you should get correct output with your code. there is nothing wrong with it.

So it is

txtNumber.Text = Sqr(txtNumber.Text)

and not

lblTroot.Caption=Sqr(txtNumber.Text)

?

*accidently posted twice

Figured it out :D It's

Private Sub cmdSquare_Click()
    'calculate square of a number
    lblTSquare.Caption = txtNumber ^ 2
    'calculate square root of a number
    lblTroot.Caption = Sqr(txtNumber.Text)

End Sub
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.