Not working, have all the buttons and labels fine, but the math part is screwing it up....help?
Public Class btnFactorial
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Friend WithEvents btnFactorial As Button 'generates output
' Visual Studio .NET generated code
Private Sub btnFactorial_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnFactorial.Click, MyBase.Click
Dim x As Double
Dim Fact As Double
lblOutput.Text = "To determine the Factorial of a number. " _
& "Please enter a number less than 10." _
& "Then, click on the Factorial Button to view the results."
x = Val(txtInput.Text)
Fact = Factorial(x)
lblOutput.Text = ("")
lblOutput.Text = (" " & x & "! is " & Fact)
End Sub ' btnFactorial_Click
' generates factorial of number
Private Function Factorial(ByVal x As Double) As Double
If x <= 1 Then ' base case
Factorial = 1
Else
Factorial = x * Factorial(x - 1)
End If
End Function ' Factorial
#End Region
Friend WithEvents lblOutput As System.Windows.Forms.Button ' prompts for integer
Friend WithEvents txtInput As System.Windows.Forms.TextBox ' reads an integer
Friend WithEvents txtDisplay As System.Windows.Forms.TextBox ' displays output
Friend WithEvents lblFactorial As System.Windows.Forms.Label ' indicates output
Friend WithEvents lblEnter As System.Windows.Forms.Label '
Private Sub InitializeComponent()
Me.lblOutput = New System.Windows.Forms.Button
Me.txtInput = New System.Windows.Forms.TextBox
Me.lblFactorial = New System.Windows.Forms.Label
Me.lblEnter = New System.Windows.Forms.Label
Me.txtDisplay = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'lblOutput
'
Me.lblOutput.BackColor = System.Drawing.SystemColors.Desktop
Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblOutput.ForeColor = System.Drawing.SystemColors.ControlLightLight
Me.lblOutput.Location = New System.Drawing.Point(78, 64)
Me.lblOutput.Name = "lblOutput"
Me.lblOutput.Size = New System.Drawing.Size(136, 40)
Me.lblOutput.TabIndex = 0
Me.lblOutput.Text = "Calculate"
'
'txtInput
'
Me.txtInput.Location = New System.Drawing.Point(184, 16)
Me.txtInput.Name = "txtInput"
Me.txtInput.Size = New System.Drawing.Size(80, 20)
Me.txtInput.TabIndex = 1
Me.txtInput.Text = "0"
'
'lblFactorial
'
Me.lblFactorial.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblFactorial.ForeColor = System.Drawing.SystemColors.ControlLightLight
Me.lblFactorial.Location = New System.Drawing.Point(82, 136)
Me.lblFactorial.Name = "lblFactorial"
Me.lblFactorial.Size = New System.Drawing.Size(128, 23)
Me.lblFactorial.TabIndex = 4
Me.lblFactorial.Text = "Factorial"
Me.lblFactorial.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lblEnter
'
Me.lblEnter.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblEnter.ForeColor = System.Drawing.SystemColors.ControlLightLight
Me.lblEnter.Location = New System.Drawing.Point(8, 8)
Me.lblEnter.Name = "lblEnter"
Me.lblEnter.Size = New System.Drawing.Size(168, 32)
Me.lblEnter.TabIndex = 5
Me.lblEnter.Text = "Enter An Integer:"
Me.lblEnter.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtDisplay
'
Me.txtDisplay.Location = New System.Drawing.Point(48, 176)
Me.txtDisplay.Name = "txtDisplay"
Me.txtDisplay.Size = New System.Drawing.Size(200, 20)
Me.txtDisplay.TabIndex = 6
Me.txtDisplay.Text = "0"
'
'btnFactorial
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Desktop
Me.ClientSize = New System.Drawing.Size(292, 334)
Me.Controls.Add(Me.txtDisplay)
Me.Controls.Add(Me.lblEnter)
Me.Controls.Add(Me.lblFactorial)
Me.Controls.Add(Me.txtInput)
Me.Controls.Add(Me.lblOutput)
Me.Name = "btnFactorial"
Me.ResumeLayout(False)
End Sub
End Class ' btnFactorial
2007-03-08
03:23:03
·
3 answers
·
asked by
bloodyhell1981
1
in
Computers & Internet
➔ Programming & Design