Jumat, 24 Oktober 2014

“Manipulasi String” dengan Visual Basic 6.0

VB6SP6_logo

Contoh latihan Visual Basic 6.0 “Manipulasi String” yang terdapat pada blog “Adam Khamarullah”.

Sedikit modifikasi yang dibuat yaitu dengan penggunaan kontrol berindex. Untuk lebih lengkapnya dapat dilihat pada kode sumber yang disertakan.

 

 

ManipulasiString

VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Manipulasi String"
ClientHeight = 7605
ClientLeft = 45
ClientTop = 330
ClientWidth = 4725
BeginProperty Font
Name = "Segoe UI"
Size = 11.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7605
ScaleWidth = 4725
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton Command1
Caption = "K&eluar"
Height = 495
Index = 1
Left = 2520
TabIndex = 19
Top = 6960
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "Proses"
Enabled = 0 'False
Height = 495
Index = 0
Left = 240
TabIndex = 18
Top = 6120
Width = 4215
End
Begin VB.TextBox Text1
Height = 420
Index = 8
Left = 1200
Locked = -1 'True
TabIndex = 17
TabStop = 0 'False
Top = 5520
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 7
Left = 1200
Locked = -1 'True
TabIndex = 15
TabStop = 0 'False
Top = 4920
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 6
Left = 1200
Locked = -1 'True
TabIndex = 13
TabStop = 0 'False
Top = 4320
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 5
Left = 1200
Locked = -1 'True
TabIndex = 11
TabStop = 0 'False
Top = 3720
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 4
Left = 1200
Locked = -1 'True
TabIndex = 9
TabStop = 0 'False
Top = 3120
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 3
Left = 1200
Locked = -1 'True
TabIndex = 7
TabStop = 0 'False
Top = 2520
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 2
Left = 1200
Locked = -1 'True
TabIndex = 5
TabStop = 0 'False
Top = 1920
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 1
Left = 1200
Locked = -1 'True
TabIndex = 3
TabStop = 0 'False
Top = 1320
Width = 3255
End
Begin VB.TextBox Text1
Height = 420
Index = 0
Left = 240
TabIndex = 1
Top = 600
Width = 4215
End
Begin VB.Line Line1
Index = 0
X1 = 240
X2 = 4440
Y1 = 6840
Y2 = 6840
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "UCASE:"
Height = 300
Index = 8
Left = 255
TabIndex = 16
Top = 5565
Width = 720
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "LCASE:"
Height = 300
Index = 7
Left = 320
TabIndex = 14
Top = 4965
Width = 675
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "RTRIM:"
Height = 300
Index = 6
Left = 320
TabIndex = 12
Top = 4365
Width = 690
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "LTRIM:"
Height = 300
Index = 5
Left = 300
TabIndex = 10
Top = 3765
Width = 660
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "LEN:"
Height = 300
Index = 4
Left = 520
TabIndex = 8
Top = 3165
Width = 435
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "MID:"
Height = 300
Index = 3
Left = 520
TabIndex = 6
Top = 2565
Width = 465
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "RIGHT:"
Height = 300
Index = 2
Left = 320
TabIndex = 4
Top = 1965
Width = 675
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "LEFT:"
Height = 300
Index = 1
Left = 480
TabIndex = 2
Top = 1365
Width = 495
End
Begin VB.Label Label
AutoSize = -1 'True
Caption = "Input Kalimat:"
Height = 300
Index = 0
Left = 240
TabIndex = 0
Top = 240
Width = 1380
End
Begin VB.Line Line1
BorderColor = &H00FFFFFF&
BorderWidth = 2
Index = 1
X1 = 240
X2 = 4440
Y1 = 6840
Y2 = 6840
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
If Command1(Index).Caption = "Proses" Then
Text1(1).Text = Left(Text1(Index).Text, 9)
Text1(2).Text = Right(Text1(Index).Text, 8)
Text1(3).Text = Mid(Text1(Index).Text, 11, 4)
Text1(4).Text = Len(Text1(Index).Text)
Text1(5).Text = LTrim(Text1(Index).Text)
Text1(6).Text = RTrim(Text1(Index).Text)
Text1(7).Text = LCase(Text1(Index).Text)
Text1(8).Text = UCase(Text1(Index).Text)
Command1(Index).Caption = "Bersihkan"
Command1(Index).SetFocus
Else
Dim i%

For i = 0 To 8
Text1(i).Text = Empty
Next

Command1(Index).Caption = "Proses"
Text1(Index).SetFocus
End If
Case 1:
Unload Me
End Select
End Sub

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Keluar program ?", vbQuestion + vbYesNo, "Perhatian") = vbNo Then
Cancel = 1
Text1(0).SetFocus
End If
End Sub

Private Sub Text1_Change(Index As Integer)
Select Case Index
Case 0:
Dim Masukan%

Masukan = Text1(Index).SelStart
Text1(Index).Text = StrConv(Text1(Index).Text, vbProperCase)
Text1(Index).SelStart = Masukan

If Len(Text1(Index).Text) > 0 Then
Command1(Index).Enabled = True
Else
Command1(Index).Enabled = False
End If
End Select
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
Dim Karakter$

Karakter = "~`!@#$%^&*()-_+=[]{}:;'<>,.?/\|"

If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then
Beep
KeyAscii = 0
ElseIf InStr(1, Karakter, Chr(KeyAscii)) > 0 Then
Beep
KeyAscii = 0
ElseIf (KeyAscii = 13) Then
Command1_Click (0)
End If
End Sub


Unduh Kode Sumber.

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda