VISUAL BASIC 6.0 (5.0) SOURCE CODE (IFCALC.FRM) :
VERSION 5.00
Begin VB.Form frmIFCalc
Caption = " Inverse Factorial Calculator [ v1.1 ]"
ClientHeight = 1320
ClientLeft = 60
ClientTop = 345
ClientWidth = 5130
Icon = "IFCalc.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
ScaleHeight = 1320
ScaleWidth = 5130
StartUpPosition = 1 'CenterOwner
Begin VB.CommandButton Command4
Caption = "Exit"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3480
TabIndex = 3
Top = 720
Width = 1455
End
Begin VB.CommandButton Command3
Caption = "Find"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 3480
TabIndex = 2
Top = 120
Width = 1455
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2520
MaxLength = 5
TabIndex = 1
Top = 120
Width = 615
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "MS Sans Serif"
Size = 13.5
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 720
MaxLength = 10
TabIndex = 0
Top = 120
Width = 1335
End
Begin VB.Label Label3
Caption = "Inverse Factorial Calculator by Erdogan Tan [ January 2002 ]"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 615
Left = 120
TabIndex = 6
Top = 600
Width = 3015
End
Begin VB.Label Label2
Caption = "E+"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 2160
TabIndex = 5
Top = 240
Width = 255
End
Begin VB.Label Label1
Caption = "n! < ="
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 162
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 4
Top = 195
Width = 495
End
End
Attribute VB_Name = "frmIFCalc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim n As Integer
Dim t As Integer
Dim u As Double
Dim v1 As Double
Dim v2 As Double
Dim Base As Single
Dim Power As Single
Dim LimitNumber As Double
Private Sub Command3_Click()
Rem Revision 1 [ 26-1-2002 ]
On Error GoTo OverFlowProblem
LimitNumber = Base ^ Power
If LimitNumber < 1 Then
Beep
MsgBox ("LimitNumber < 1" + Chr$(13) + Chr$(13) + "[ 0! = 1 ]"), 0, "! INVALID INPUT !"
Exit Sub
End If
n = 1
v1 = 0
Calculate:
v2 = Factorial(n)
If v2 <= LimitNumber Then
n = n + 1
v1 = v2
GoTo Calculate
Else
n = n - 1
Beep
MsgBox ("Number =" + Str$(n)) + Chr$(13) + Chr$(13) + "Factorial =" + Str$(v1) + Chr$(13) + Chr$(13) + "[ Limit =" + Str$(LimitNumber) + " ]", 0, " Inverse Factorial Calculator by Erdogan Tan"
End If
EndOfCommand:
Text1.SetFocus
Exit Sub
OverFlowProblem:
Beep
MsgBox ("OverFlow Problem !" + Chr$(13) + Chr$(13) + "[ The Number is over big for 'Double' variable. ]"), 48, "! ERROR !"
Resume EndOfCommand
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Form_Activate()
Label3.Caption = "Enter the Limit of 'n!' for finding the number 'n'."
End Sub
Private Function Factorial(n As Integer) As Double
Rem Factorial Calculating Method by Erdogan Tan (21/7/2001)
If n = 0 Then
Factorial = 1
Else
u = 1
For t = 1 To n
u = u * t
Next t
Factorial = u
End If
End Function
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then
End
Else
If KeyCode = &H79 Then
Rem Version 1.0 [ 23-1-2002 ]
Rem Version 1.1 [ 26-1-2002 ]
Beep
MsgBox ("F1= Calculate" + Chr$(13) + Chr$(13) + "F10= Info/Help" + Chr$(13) + Chr$(13) + "ESC= Exit"), 0, " Inverse Factorial Calculator Version 1.1"
Text1.SetFocus
Else
If KeyCode = &H70 Then
Command3_Click
End If
End If
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text2.SetFocus
End Sub
Private Sub Text1_LostFocus()
Base = Val(Text1.Text)
Text1.Text = LTrim(Str$(Base))
Power = Val(Text2.Text)
Text2.Text = LTrim(Str$(Power))
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Command3.SetFocus
End Sub
Private Sub Text2_LostFocus()
Power = Val(Text2.Text)
Text2.Text = LTrim(Str$(Power))
End Sub
Last Update: 26/1/2002