combination


Dim flag As Boolean
Public Sub Engine(char As String, length As Byte)

ReDim ary(length)
Dim depth As Byte
Dim result As String

depth = 1

While Not (flag)
k = DoEvents()
ary(depth) = ary(depth) + 1

If depth = length Then
result = Left(result, length – 1) + Mid(char, ary(depth), 1)
Else
result = result + Mid(char, ary(depth), 1)
End If

If ary(depth) <> Len(char) + 1 Then
If depth <> length Then
depth = depth + 1
Else
List1.AddItem result
If ChSave.Value = 1 Then Print #1, result
End If
Else
If depth = 1 Then
flag = True
Else
ary(depth) = 0
depth = depth – 1
result = Left(result, depth – 1)
End If
End If
Wend
End Sub

Private Sub InitValue(start As Boolean)
flag = start

ChSave.Enabled = start
txtChar.Enabled = start
txtLength.Enabled = start
If start Then
cmdGen.Caption = “Generate”
Else
cmdGen.Caption = “Stop”
End If
End Sub

Private Sub cmdGen_Click()
If Val(txtLength.Text) > Len(txtChar.Text) Then
MsgBox “Jumlah Kombinasi Salah”
Exit Sub
End If

If Len(txtChar.Text) = 0 Or (Val(txtLength.Text) = 0) Then
Exit Sub
End If

If cmdGen.Caption = “Generate” Then
InitValue False
If ChSave.Value = 1 Then
MsgBox “Disimpan pada hasil.txt”
Open App.Path + “\hasil.txt” For Output As #1
End If
Call Engine(txtChar.Text, txtLength.Text)
If ChSave.Value = 1 Then Close #1
InitValue True
Else
InitValue True
End If
End Sub

Private Sub CmdClear_Click()
List1.Clear
End Sub

Private Sub Form_Load()
List1.Clear
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s