Click to See Complete Forum and Search --> : NEED HELP


Orphette
May 22nd, 2001, 03:29 AM
Im new at doing this Vb and im not understanding the variables to well. I have to code the square root button so that it calculates and displays the square root of a whole number. I have to assign a numeric equivalent of the txtNumber.text property to an integer variable. And assign the square root to a single variable. All using the Sqr function to calculate. Can anyone help me with this? And try and explain to me how to get to remember all the variables? I really appreciate any help Thankyou.

Tower
May 22nd, 2001, 03:50 AM
i = Sqr(txtNumber.Text)



After this variable i contents needed value.

Cimperiali
May 22nd, 2001, 04:17 AM
...and (read tower answer, first) you may want to put it under the click event of a command button. So, add a command button to your form, change its name to cmdSquare (just for better understanding), then double click on it, and you will have the place where to put Tower code
Private Sub cmdSquare_click()
'codes go here
Dim i As Integer
'check if it is a number
If IsNumeric(text1.Text) Then
'make some conversions: sqr expect a double
'while text1 is a string
'while i is integer.
'Vb will do it for you, but you may want
'to set it manually. Look at differences between
'Cint and Int functions about rounding numbers...
i = CInt(Sqr(CDbl(text1.Text)))
'..do what you need with i
Else
MsgBox "You did not insert a number in TextBox"
End If
End Sub

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Cimperiali
May 22nd, 2001, 04:20 AM
whoops, made a mistake!
dim i as integer is not correct, you spoike about a single variable!
substitute it with
dim sngNumber as single
and instead of
i= =cint(...
write
sngNumber=CSng(...

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.