|
-
May 22nd, 2001, 03:29 AM
#1
NEED HELP
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.
-
May 22nd, 2001, 03:50 AM
#2
Re: NEED HELP
i = Sqr(txtNumber.Text)
After this variable i contents needed value.
Andy Tower
-
May 22nd, 2001, 04:17 AM
#3
Re: NEED HELP
...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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
May 22nd, 2001, 04:20 AM
#4
Re: NEED HELP
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|