Wednesday 8 February 2012

Deterministic Finite Automata (DFA) Simulator Visual Basic 6.0

 1. Buat alur DFA sebagai berikut, jangan ada perubahan. silakan d uat menggunakan sofware editing yang anda kuasai atau save gambar dari blog saya ini





2. Buat tampilan form di VB sesuai gambar di bawah ini

letakkan gambar yang tadi dibuat sebagai background


3. Buat satu modul

codenya sebagai berikut

Public Sub Fokus(ByVal KotakTesk As TextBox)
    With KotakTesk
        .SelStart = 0
        .SelLength = Len(.Text)
        .SetFocus
    End With
End Sub

3. Buka form code lalu tuliskan code berikut


Option Explicit
Dim P1, P2, P3, P4, P5 As Boolean
Dim Q1, Q2, Q3, Q4, Q5 As Boolean
Dim R1, R2, R3, R4, R5 As Boolean
Dim S1, S2, S3, S4, S5 As Boolean
Dim T1, T2, T3, T4, T5 As Boolean
Dim inputan, w, indx As Integer
Dim accept, refuses As String
Dim LenTemp, strTemp, n

Private Sub cclos_Click()
Unload Me
End Sub

Private Sub Cnew_Click()
awal
Text1.SetFocus
general.Enabled = False
w = 0
End Sub

Private Sub Cpro_Click()
general.Enabled = True
pasif
Cnew.SetFocus
End Sub

Private Sub Cpro_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Cnew.SetFocus
If KeyAscii = 27 Then Fokus Text5
End Sub

Private Sub Form_Load()
awal
accept = "terima"
refuses = "tolak"
strTemp = Me.Caption
n = 1
End Sub

Private Sub general_Timer()
w = w + 1
If w = 150 Then general.Enabled = False

Select Case w
    Case 0 To 25
    indx = 1
    Case 26 To 50
    inputan = Text1.Text
    indx = 2
    Case 51 To 75
    inputan = Text2.Text
    indx = 3
    Case 76 To 100
    inputan = Text3.Text
    indx = 4
    Case 101 To 125
    inputan = Text4.Text
    indx = 5
    Case 126 To 150
    inputan = Text5.Text
    indx = 6
End Select
macin
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Fokus Text2
If KeyAscii = 27 Then cclos.SetFocus
If KeyAscii = 8 Then
            KeyAscii = KeyAscii
        Else
            If KeyAscii < Asc("0") Or KeyAscii > Asc("1") Then
            KeyAscii = 0
      
        End If
    End If

End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Fokus Text3
If KeyAscii = 27 Then Fokus Text1
If KeyAscii = 8 Then
            KeyAscii = KeyAscii
        Else
            If KeyAscii < Asc("0") Or KeyAscii > Asc("1") Then
            KeyAscii = 0
      
        End If
    End If

End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Fokus Text4
If KeyAscii = 27 Then Fokus Text2
If KeyAscii = 8 Then
            KeyAscii = KeyAscii
        Else
            If KeyAscii < Asc("0") Or KeyAscii > Asc("1") Then
            KeyAscii = 0
      
        End If
    End If

End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Fokus Text5
If KeyAscii = 27 Then Fokus Text3
If KeyAscii = 8 Then
            KeyAscii = KeyAscii
        Else
            If KeyAscii < Asc("0") Or KeyAscii > Asc("1") Then
            KeyAscii = 0
      
        End If
    End If

End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
        aktif
        If Cpro.Enabled = True Then
        Cpro.SetFocus
        Else
        Cnew.SetFocus
        End If
    End If
If KeyAscii = 27 Then Fokus Text4
If KeyAscii = 8 Then
            KeyAscii = KeyAscii
        Else
            If KeyAscii < Asc("0") Or KeyAscii > Asc("1") Then
            KeyAscii = 0
      
        End If
    End If

End Sub

Private Sub Timer1_Timer()
LenTemp = Len(strTemp)
    Dim Form As String
    LenTemp = Len(strTemp)
    Me.Caption = Left(strTemp, n) + "_"
    n = n + 1
    If n > LenTemp Then
        n = 1
    End If
End Sub

Private Sub TimP_Timer()
P.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End Sub

Private Sub TimQ_Timer()
Q.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End Sub

Private Sub TimR_Timer()
R.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End Sub

Private Sub TimS_Timer()
S.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End Sub

Private Sub TimT_Timer()
T.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
X.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

End Sub

Sub awal()
TimP.Enabled = False
TimQ.Enabled = False
TimR.Enabled = False
TimS.Enabled = False
TimT.Enabled = False
general.Enabled = False
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Label4.Caption = ""
P1 = False
P2 = False
P3 = False
P4 = False
P5 = False
Q1 = False
Q2 = False
Q3 = False
Q4 = False
Q5 = False
R1 = False
R2 = False
R3 = False
R4 = False
R5 = False
S1 = False
S2 = False
S3 = False
S4 = False
S5 = False
T1 = False
T2 = False
T3 = False
T4 = False
T5 = False
P.FillColor = vbBlack
Q.FillColor = vbBlack
R.FillColor = vbBlack
S.FillColor = vbBlack
T.FillColor = vbBlack
X.FillColor = vbWhite
pasif
End Sub

Sub macin()
Select Case indx
Case 1
    val_p
Case 2
    Select Case inputan
        Case 0
        val_q
        Q1 = True
        Case 1
        val_s
        S1 = True
    End Select
Case 3
    Select Case inputan
        Case 0
            If Q1 = True Then
                val_s
                S2 = True
            Else
            If S1 = True Then
                val_r
                R2 = True
            End If
            End If
        Case 1
        If Q1 = True Then
                val_r
                R2 = True
            Else
            If S1 = True Then
                val_t
                T2 = True
            End If
            End If
     End Select
Case 4
    Select Case inputan
    Case 0
        If S2 = True Then
                val_r
                R3 = True
            Else
        If R2 = True Then
                val_t
                T3 = True
            Else
        If T2 = True Then
                val_p
                P3 = True
            End If
        End If
    End If
    Case 1
         If S2 = True Then
                val_t
                T3 = True
            Else
        If R2 = True Then
                val_q
                Q3 = True
            Else
        If T2 = True Then
                val_r
                R3 = True
            End If
        End If
    End If
    End Select
Case 5
    Select Case inputan
        Case 0
            If R3 = True Then
                val_t
                T4 = True
            Else
            If T3 = True Then
                val_p
                P4 = True
            Else
            If P3 = True Then
                val_q
                Q4 = True
            Else
            If Q3 = True Then
                val_s
                S4 = True
            End If
            End If
        End If
        End If
    Case 1
        If R3 = True Then
                val_q
                Q4 = True
            Else
            If T3 = True Then
                val_r
                R4 = True
            Else
            If P3 = True Then
                val_s
                S4 = True
            Else
            If Q3 = True Then
                val_r
                R4 = True
            End If
            End If
        End If
        End If
    End Select
Case 6
    Select Case inputan
        Case 0
            If T4 = True Then
                val_p
                Label4.Caption = refuses
            Else
            If S4 = True Then
                val_r
                Label4.Caption = refuses
            Else
            If R4 = True Then
                val_t
                Label4.Caption = accept
            Else
            If Q4 = True Then
                val_s
                Label4.Caption = refuses
            Else
            If P4 = True Then
                val_q
                Label4.Caption = refuses
                End If
            End If
        End If
        End If
        End If
    Case 1
            If T4 = True Then
                val_r
                Label4.Caption = refuses
            Else
            If S4 = True Then
                val_t
                Label4.Caption = accept
            Else
            If R4 = True Then
                val_q
                Label4.Caption = refuses
            Else
            If Q4 = True Then
                val_r
                Label4.Caption = refuses
            Else
            If P4 = True Then
                val_s
                Label4.Caption = refuses
                End If
            End If
        End If
        End If
        End If
    End Select
End Select
End Sub

Sub val_p()
TimP.Enabled = True
TimQ.Enabled = False
Q.FillColor = vbBlack
TimR.Enabled = False
R.FillColor = vbBlack
TimS.Enabled = False
S.FillColor = vbBlack
TimT.Enabled = False
T.FillColor = vbBlack
X.FillColor = vbWhite

End Sub

Sub val_q()
TimP.Enabled = False
P.FillColor = vbBlack
TimQ.Enabled = True
TimR.Enabled = False
R.FillColor = vbBlack
TimS.Enabled = False
S.FillColor = vbBlack
TimT.Enabled = False
T.FillColor = vbBlack
X.FillColor = vbWhite

End Sub
Sub val_r()
TimP.Enabled = False
P.FillColor = vbBlack
TimQ.Enabled = False
Q.FillColor = vbBlack
TimR.Enabled = True
TimS.Enabled = False
S.FillColor = vbBlack
TimT.Enabled = False
T.FillColor = vbBlack
X.FillColor = vbWhite


End Sub
Sub val_s()
TimP.Enabled = False
P.FillColor = vbBlack
TimQ.Enabled = False
Q.FillColor = vbBlack
TimR.Enabled = False
R.FillColor = vbBlack
TimS.Enabled = True
TimT.Enabled = False
T.FillColor = vbBlack
X.FillColor = vbWhite


End Sub
Sub val_t()
TimP.Enabled = False
P.FillColor = vbBlack
TimQ.Enabled = False
Q.FillColor = vbBlack
TimR.Enabled = False
R.FillColor = vbBlack
TimS.Enabled = False
S.FillColor = vbBlack
TimT.Enabled = True


End Sub



Sub pasif()
Cpro.Enabled = True
End Sub

Sub aktif()
If Not Text1.Text = "" And Not Text2.Text = "" And Not Text3.Text = "" And Not Text4.Text = "" And Not Text5.Text = "" Then
Cpro.Enabled = True
End If
End Sub


posting dari  blog nya:

No comments:

Post a Comment