VISUAL BASIC 6.0 (5.0) SOURCE CODE (COMBIN.FRM) :
VERSION 5.00 Begin VB.Form frmCombin Caption = " BASIC COMBINATOR by Erdogan Tan" ClientHeight = 2160 ClientLeft = 60 ClientTop = 345 ClientWidth = 5085 Icon = "COMBIN.frx":0000 KeyPreview = -1 'True LinkTopic = "Form1" ScaleHeight = 2160 ScaleWidth = 5085 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 = 3360 TabIndex = 5 Top = 1560 Width = 1575 End Begin VB.CommandButton Command3 Caption = "Factorial" 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 = 3360 TabIndex = 4 Top = 1080 Width = 1575 End Begin VB.CommandButton Command2 Caption = "Combination" 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 = 3360 TabIndex = 3 Top = 600 Width = 1575 End Begin VB.CommandButton Command1 Caption = "Permutation" 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 = 3360 TabIndex = 2 Top = 120 Width = 1575 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 = 1440 MaxLength = 4 TabIndex = 1 Text = "0" Top = 600 Width = 735 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 = 1440 MaxLength = 4 TabIndex = 0 Text = "0" Top = 120 Width = 735 End Begin VB.Label Label3 Caption = "BASIC COMBINATOR Version 2.0 by Erdogan Tan [ 26-1-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 = 855 Left = 120 TabIndex = 8 Top = 1200 Width = 3015 End Begin VB.Label Label2 Caption = "Number ""r"" =" 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 = 7 Top = 720 Width = 1335 End Begin VB.Label Label1 Caption = "Number ""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 = 6 Top = 195 Width = 1335 End End Attribute VB_Name = "frmCombin" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim r As Integer Dim n As Integer Dim t As Integer Dim u As Double Dim v As Double Private Sub Command1_Click() Rem Revision 1 [ 26-1-2002 ] v2.0 u = Permutation(n, r) If u >= 0 Then Beep MsgBox ("Permutation(n,r) =" + Str$(u) + Chr$(13) + Chr$(13) + "[ n=" + Str$(n) + ", r=" + Str$(r) + " ]"), 0, " BASIC COMBINATOR v2.0" Else Beep MsgBox ("Permutation Value is > 10^306 !" + Chr$(13) + Chr$(13) + "[ Overflow Problem ! ]"), 48, " ! ERROR !" End If Text1.SetFocus End Sub Private Sub Command2_Click() Rem Revision 1 [ 26-1-2002 ] v2.0 If r > 170 Then Beep MsgBox ("Maximum acceptable value is 10^306 !" + Chr$(13) + Chr$(13) + "[ 'r' must be <= 170 ]"), 48, " ! OVERFLOW !" Else u = Combination(n, r) If u >= 0 Then Beep MsgBox ("Combination(n,r) =" + Str$(u) + Chr$(13) + Chr$(13) + "[ n=" + Str$(n) + ", r=" + Str$(r) + " ]"), 0, " BASIC COMBINATOR v2.0" Else Beep MsgBox ("Permutation value is > 10^306 !" + Chr$(13) + Chr$(13) + "[ Overflow Problem ]"), 48, " ! ERROR !" End If End If Text1.SetFocus End Sub Private Sub Command3_Click() Rem Revision 1 [ 26-1-2002 ] v2.0 If n > 170 Then Beep MsgBox ("'n!' value is > 10^306 !" + Chr$(13) + Chr$(13) + "[ 'n' must be <= 170 ]"), 48, " ! OVERFLOW !" v = 0 Else v = Factorial(n) End If If r > 170 Then Beep MsgBox ("'r!' value is > 10^306 !" + Chr$(13) + Chr$(13) + "[ 'r' must be <= 170 ]"), 48, " ! OVERFLOW !" u = 0 Else u = Factorial(r) End If Beep MsgBox ("n! =" + Str$(v) + Chr$(13) + "r! =" + Str$(u) + Chr$(13) + Chr$(13) + "[ n=" + Str$(n) + ", r=" + Str$(r) + " ]"), 0, " BASIC COMBINATOR v2.0" Text1.SetFocus End Sub Private Sub Command4_Click() End End Sub Private Sub Form_Activate() Label3.Caption = "Permutation(n,r)= n! / (n-r)!" + Chr$(13) + "Combination(n,r)= n! / ((n-r)!*r!)" + Chr$(13) + "Factorial(n)= n*(n-1)*(n-2)...*1 = n!" End Sub Private Function Permutation(n As Integer, r As Integer) As Double Rem Permutation Calculator Version 2.0 by Erdogan Tan [ 26/1/2002 ] Rem Version 1.0 [ 24/7/2001 ] Rem *** Rem Calculates and returns permutation value Rem for r elements of total n elements... Rem *** If n < 1 Or r < 1 Then Permutation = 0 Rem invalid input values Else If r > n Then Permutation = 0 Else On Error GoTo PHata u = 1 For t = (n - r) + 1 To n u = u * t Next t Permutation = u Rem Permutatiton(n,r) is calculated as above Rem Permutation(n,r) = (n!)/(n-r)! Rem (n!)/(n-r!) = ((n-r)+1)*((n-r)+2)*....*n End If End If ExitPF: Exit Function PHata: Permutation = -1 Resume ExitPF End Function Private Function Combination(n As Integer, r As Integer) As Double Rem Combination Calculation Version 2.0 by Erdogan Tan [ 26/1/2002 ] Rem Version 1.1 [ 24/7/2001 ] Rem *** Rem Calculates and returns all of possible combinations Rem with r different elements of total n elements... Rem *** If n < 1 Or r < 1 Then Combination = 0 Rem invalid input values Else If r > n Then Combination = 0 Else If r = n Then Combination = 1 Else On Error GoTo CHata u = 1 For t = (n - r) + 1 To n u = u * t Next t Rem Permutation(n,r) is calculated as above v = 1 For t = 1 To r v = v * t Next t Rem r! is calculated as above Rem r!= 1*...*(r-1)*r Combination = (u / v) Rem Combination = n! / ((n-r)! * r!) Rem Combination(n,r) = Permutation(n,r) / r! Rem (n!)/(n-r!) = ((n-r)+1)*((n-r)+2)*....*n End If End If End If ExitCF: Exit Function CHata: Combination = -1 Resume ExitCF End Function 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 Rem n! is calculated as above Rem n!= 1*...*(n-1)*n End If End Function Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then End Else If KeyCode = &H79 Then Beep MsgBox ("F1= Permutation , F2= Combination , F3= Factorial" + Chr$(13) + Chr$(13) + "F10= Info/Help" + Chr$(13) + Chr$(13) + "ESC= Exit"), 0, " BASIC COMBINATOR Version 2.0 [ 26/1/2002 ]" Text1.SetFocus Else If KeyCode = &H70 Then Command1_Click Else If KeyCode = &H71 Then Command2_Click Else If KeyCode = &H72 Then Command3_Click Else If KeyCode > &H72 And KeyCode < &H77 Then Text1.SetFocus End If End If End If 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() n = Val(Text1.Text) Text1.Text = n End Sub Private Sub Text2_Keypress(KeyAscii As Integer) If KeyAscii = 13 Then Command1.SetFocus End Sub Private Sub Text2_LostFocus() r = Val(Text2.Text) Text2.Text = r End Sub
Last Update: 21/03/2004