Loop In Visual Basic.Net

Looping is one of the basic algorithms which can be found in all programming language like C++, Java, Pascal and so Visual Basic.Net. In this session we can try to make program Looping using Visual Basic.Net for. In Visual Basic.Net, there are many kinds of looping, but in this case, we can just Loop with For..Next, here we are :
1. Go to your Visual Basic.net via your visual studio.net
2. design the Form, like a picture above
3. setting properties for each component; let's say for your textbox1named txtId, for button of 'simpan' named btnSimpan, etc
4. type the code bellow :
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
If indeks_data > jml_data - 1 Then
MsgBox("List sudah penuh")
Else
data_lecturer(indeks_data, 0) = txtNoInduk.Text
data_lecturer(indeks_data, 1) = txtNama.Text
data_lecturer(indeks_data, 2) = txtAlamat.Text
data_lecturer(indeks_data, 3) = txtTelpon.Text
txtNoInduk.Text = ""
txtNama.Text = ""
txtAlamat.Text = ""
txtTelpon.Text = ""
txtNoInduk.Focus()
indeks_data = indeks_data + 1
End If
End Sub

Private Sub btnLihat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLihat.Click
Dim i As Byte
listno_induk.Items.Clear()
listNama.Items.Clear()
listAlamat.Items.Clear()
listTelpon.Items.Clear()
If indeks_data > 0 Then
For i = 0 To indeks_data - 1
listno_induk.Items.Add(data_lecturer(i, 0))
listNama.Items.Add(data_lecturer(i, 1))
listAlamat.Items.Add(data_lecturer(i, 2))
listTelpon.Items.Add(data_lecturer(i, 3))
Next
End If
End Sub

Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
End
End Sub
5. Well, don't forget, we have to make global identifiers, put the code bellow, after Public.... if You use Visual basic.Net 2005, but if you use previous visual studio.net (2003), you have to put the code after Public class FmForNext ..., Inherits System.Windows.Forms.Form, here is the code
Dim jml_data As Byte = 5
Dim indeks_data As Byte = 0
Dim data_lecturer(5, 4) As String
6. Build the program, and Execute, Have a try it :).

Created By Ader

Popular posts from this blog

Introduction to Use Case Diagram - Case study: Facebook

Kenapa tidak berkurban?

Sequential Search