Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 137,363 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,818 people online right now. Registration is fast and FREE... Join Now!




Can anybody find an error?

 
Reply to this topicStart new topic

Can anybody find an error?, Factorial Function

nemse
8 Oct, 2008 - 05:59 AM
Post #1

New D.I.C Head
*

Joined: 7 Oct, 2008
Posts: 4

This code seems to be working well.
But I just wanted to make sure if everything is OK.

vb

Public Class Factorial

Private Sub CalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateButton.Click

Dim x As Double
Dim Fact As Double

x = Val(NumberTextbox.Text)

Fact = Factorial(x)
ResultLabel.Text = Fact


End Sub

Private Function Factorial(ByRef x As Double) As Double


If x <= 1 Then
Factorial = 1
Else
Factorial = x * Factorial(x - 1)
End If

End Function

End Class


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

Reverand Dave
RE: Can Anybody Find An Error?
8 Oct, 2008 - 06:06 AM
Post #2

D.I.C Regular
Group Icon

Joined: 27 Jul, 2008
Posts: 373



Thanked: 2 times
Dream Kudos: 50
My Contributions
looks like this is VB.NET
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Can Anybody Find An Error?
8 Oct, 2008 - 07:20 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,009



Thanked: 126 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

Locke37
RE: Can Anybody Find An Error?
8 Oct, 2008 - 07:26 AM
Post #4

I'm not a thief...I prefer the term TREASURE HUNTER!
Group Icon

Joined: 20 Mar, 2008
Posts: 1,059



Thanked: 41 times
Dream Kudos: 325
My Contributions
Yeah, your code is fine. It's just a basic recursive function.

smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 01:09AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month