VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Permutation

by Peter Elisa Souhoka (21 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 16th May 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Permutation

Rate Permutation




Dim id As Integer
Dim N As Integer
Dim perm() As Integer

Function Engine(i As Integer)
   Dim t As Integer
   Dim j As Integer
   
   id = id + 1
   perm(i) = id
   If (id = N) Then stampaj
   For j = 1 To N
      If (perm(j) = 0) Then
         Engine (j)
      End If
   DoEvents
   Next j
   id = id - 1
   perm(i) = 0
End Function

Private Sub cmdClear_Click()
  List1.Clear
End Sub

Private Sub cmdGen_Click()
  If Val(txtLength.Text) > Len(txtChar.Text) Then
    MsgBox "Failled"
    Exit Sub
  End If
   
  If Len(txtChar.Text) = 0 Or (Val(txtLength.Text) = 0) Then Exit Sub
  
  Dim i As Integer
  N = Val(txtLength.Text)
  ReDim perm(N)
  For i = 1 To N
     perm(i) = 0
  Next i
  If ChSave.Value = 1 Then
     MsgBox "Save To Hasil.txt"
     Open App.Path + "\hasil.txt" For Output As #1
  End If
  Engine 0
  If ChSave.Value = 1 Then Close #1
  
End Sub

Sub Form_Load()
   On Error Resume Next
   id = -1
   
End Sub

Sub stampaj()
   Dim i As Integer
   Dim result As String
   result = ""
   For i = 1 To N
      result = result & CStr(Mid$(txtChar.Text, perm(i), 1))
   Next i
   List1.AddItem result
   If ChSave.Value = 1 Then Print #1, result
End Sub




Download this snippet    Add to My Saved Code

Permutation Comments

No comments have been posted about Permutation. Why not be the first to post a comment about Permutation.

Post your comment

Subject:
Message:
0/1000 characters