[ VB.NET ] Looping Ketupat VB.Net 2008
Berasal dari Tugas kuliah Jadinya tau kl ad looping yg unik2 begini...
Looping ini Jika kita memasukkan angka d textbox dn klik show maka Pada textbox akan tampil bintang2 yg berbentuk belah ketupat
Ok lsng saja d simak langkah2 berikut :
Looping ini Jika kita memasukkan angka d textbox dn klik show maka Pada textbox akan tampil bintang2 yg berbentuk belah ketupat
Ok lsng saja d simak langkah2 berikut :
LANGAKAH – LANGKAH PEMBUATAN
1. Buat projek
dan 1 buah form
2. Pada
form1 Atur Propertiees Seperti Berikut :
NAMA
|
PROPERTIES
|
TEXT
|
GROUPBOX
|
-
|
-
|
GROUPBOX
|
-
|
Masukkan angka dan klik Show
|
TEXTBOX
|
NAME : TxtAngka
|
-
|
BUTTON1
|
NAME :BtnShow
|
SHOW
|
BUTTON2
|
NAME :BtnClose
|
X
|
BUTTON3
|
NAME :BtnClear
|
Clear
|
LISTBOX
|
FONT : COURIER NEW
|
|
CONTROLBOX(properties)
|
FALSE
|
**Berilah warna Pada Text Biar Lebih Menarik
3. Double
click pada sembarang form lalu ketikkan kode berikut :
Private Sub
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
BtnClear.Enabled = False
End Sub
4. Double
click pada btnShow, lalu ketikan Kode Berikut :
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim
Teks As String
Dim N As Integer =
TextBox1.Text
Dim Cek
As Boolean = True
Dim Sw As Byte = 1
Do While cek
If
sw = 1 Then
For
A As Integer =
1 To N
For
B As Integer =
1 To A
teks &= B
Next
For
C As Integer =
A - 1 To 1 Step
-1
teks &= C
Next
ListBox1.Items.Add(Space(N
- A) & teks)
teks = ""
Next
sw = 0
Else
For
A As Integer =
N - 1 To 1 Step
-1
For
b As Integer =
1 To A
teks &= b
Next
For
c As Integer =
A - 1 To 1 Step
-1
teks &= c
Next
ListBox1.Items.Add(Space(N
- A) & teks)
teks = ""
Next
cek = False
End
If
Loop
BtnClear.Enabled = True
BtnShow.Enabled = False
End Sub
5. Double
click pada BtnClear dan Ketikkan Kode Berikut :
Private Sub
BtnClear_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
BtnClear.Click
ListBox1.Items.Clear()
BtnShow.Enabled
= True
BtnClear.Enabled = False
End Sub
6. Double clik
pada BtnClose, lalu ketikan Kode Berikut :
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button2.Click
Dim pesan As String
pesan = MsgBox("Keluar?", MsgBoxStyle.Question +
MsgBoxStyle.YesNo, "Ketupat")
If pesan = vbYes Then
Me.Close()
End If
End Sub
7. Double click
pada TxtAngka dan ganti decalaration menjadi KEYPREES Lalu ketikan Kode Berikut :
Private Sub
TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress
If (e.KeyChar < Chr(48) Or
e.KeyChar > Chr(57)) And e.KeyChar <>
Chr(8) And e.KeyChar <> Chr(Asc(".")) Then
e.Handled =
True
End If
End Sub
8. Jalankan
dengan menekan tombol F5, Jika Benar maka hasilnya seperti Berikut :
baca juga form tambah simpan Vb.net Disini
mana kodingnya??
ReplyDeleteSilahkan cek
ReplyDelete