Permutasi Visual Basic

Posted on January 14, 2010
Filed Under VISUAL BASIC | Leave a Comment

Option Explicit
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 “Jumlah Permutasi Salah”
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 “Disimpan pada 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

Comments

Leave a Reply




  • Communities

    bloggersumut.net
  • Recent Visitorz

  • blog visitors

    free html visitor counters
  • online status

  • Jam

  • live on twitter