|
-
Oct 25th, 2002, 08:19 AM
#1
Thread Starter
New Member
problem with the function(square root)
i have a problem with the function of a square root. anyone here who knows how to decode a square function into a VB codes would be grealy appreciated
-
Oct 25th, 2002, 08:22 AM
#2
Frenzied Member
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 25th, 2002, 08:24 AM
#3
Retired VBF Adm1nistrator
VB Code:
Private Sub Form_Load()
MsgBox SquareRoot(9)
End Sub
Private Function SquareRoot(ByVal n As Long) As Single
SquareRoot = n ^ (1 / 2)
End Function
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 25th, 2002, 08:25 AM
#4
There is also a built in function in VB that will return a Square Root. It is SQR. Example
-
Oct 25th, 2002, 08:29 AM
#5
Retired VBF Adm1nistrator
Ya know, I didn't know that actually!
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 25th, 2002, 08:32 AM
#6
Frenzied Member
Is that what he wanted?
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 25th, 2002, 08:33 AM
#7
Originally posted by plenderj
Ya know, I didn't know that actually!
Me either until I did web search on Square Root and the first flippin' hit I got told me about that VB function. LOL
So, I looked it up in VB Help, and there it was.
PS: plenderj congrats on 7k
-
Oct 25th, 2002, 08:36 AM
#8
Retired VBF Adm1nistrator
Cheers.
I'll be congratulating you on 10k soon!
... should send megatron a pm too about that
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Oct 25th, 2002, 08:39 AM
#9
Fanatic Member
Wow, and I found out about it in the 3rd chapter of the first VB-programming book I ever read. (72 chapters in total... Mostly about 5 pages per chap. so no need to go )
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Oct 25th, 2002, 08:40 AM
#10
Frenzied Member
Do I take it that my question was answered in the positive?
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 25th, 2002, 08:41 AM
#11
Fanatic Member
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Oct 25th, 2002, 08:45 AM
#12
Frenzied Member
silly me! I was busy porting an old Babylonian Series to generate the square root the hard way!
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Oct 25th, 2002, 08:50 AM
#13
Fanatic Member
For sq.rooting with other exponents:
VB Code:
Public Function Root(Exponent As Integer, Number As Long) As Single
Root = Number ^ (1 / Exponent)
End Function
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Oct 25th, 2002, 08:58 AM
#14
Frenzied Member
Well, for what its worth
VB Code:
Private Function SquareRoot(thenumber As Double)
Dim theVals() As Double
ReDim theVals(1 To thenumber)
theVals(1) = (1 / 2) + (k / 2)
For i = 2 To thenumber
theVals(i) = (theVals(i - 1) / 2) + (thenumber / (2 * theVals(i - 1)))
If theVals(i) = theVals(i - 1) Then
SquareRoot = theVals(i)
Exit Function
End If
Next i
End Function
Private Sub Command1_Click()
MsgBox Round(SquareRoot(256), 16) & vbCrLf & vbCrLf & Round(Sqr(256), 16)
MsgBox Round(SquareRoot(10000), 16) & vbCrLf & vbCrLf & Round(Sqr(10000), 16)
MsgBox Round(SquareRoot(123456), 16) & vbCrLf & vbCrLf & Round(Sqr(123456), 16)
MsgBox Round(SquareRoot(123.456), 16) & vbCrLf & vbCrLf & Round(Sqr(123.456), 16)
End Sub
The above uses no exponentiation. only add, sub, mul, and div.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
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
|