Senin, 23 November 2015

Cara Membuat Lampu Lalu Lintas, Kalkulator dan Menghitung Luas Di VB.Net

Langkah awal yang harus anda lakukan untuk memulai, yaitu ikuti langkah-langkah berikut:
1.   Buka aplikasi Visual Studio, maka akan muncul tampilan seperti berikut.
 
2.   Klik pada menu New Project.
3.   Maka akan muncul tampilan seperti berikut, ikuti langkah-langkah pada
      image berikut.
4.  Muncul sebuah jendela loading, tunggu proses loading selesai hingga
     VB.Net siap digunakan.
5.   Jika sudah tampil tampilan berikut ini, maka VB.Net anda siap digunakan.
Nah ....
Friends, berikut ini adalah beberapa study kasus yang pernah saya temui. Tujuan saya post ini adalah sebagai bahan pelajaran saja, sekaligus untuk membatu teman-teman untuk belajar VB.Net. Langsung saja yahhh ...
Soal yang pertama, yaitu kita akan membuat program untuk Lampu Lalu Lintas, pastinya teman-teman semua tahukan apa itu lampu lalu Lintas ?

1.   Membuat Lampu Lalu Lintas

Coding :
Public Class Form1
    Dim time, waktu1, waktu2, waktu3, waktu4 As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
        time = 0
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        time = time + Timer1.Interval
        Select Case time
            Case 1000
                hij1.BackColor = Color.FromArgb(0, 255, 0)
                mer3.BackColor = Color.Red
                mer2.BackColor = Color.Red
                mer4.BackColor = Color.Red
                kun2.BackColor = Color.FromArgb(64, 64, 0)
                kun1.BackColor = Color.FromArgb(64, 64, 0)
                lblT1.Text = "Jalur 1 silahkan Jalan"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 belok kiri jalan terus"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 11000
                hij1.BackColor = Color.FromArgb(0, 64, 0)
                kun1.BackColor = Color.Yellow
                kun3.BackColor = Color.Yellow
                mer3.BackColor = Color.FromArgb(64, 0, 0)
                mer2.BackColor = Color.Red
                mer4.BackColor = Color.Red
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 silahkan Jalan"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 12000
                hij3.BackColor = Color.FromArgb(0, 255, 0)
                mer1.BackColor = Color.Red
                mer2.BackColor = Color.Red
                mer4.BackColor = Color.Red
                kun1.BackColor = Color.FromArgb(64, 64, 0)
                kun3.BackColor = Color.FromArgb(64, 64, 0)
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 silahkan Jalan"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 21000
                hij3.BackColor = Color.FromArgb(0, 64, 0)
                mer1.BackColor = Color.Red
                mer2.BackColor = Color.FromArgb(64, 0, 0)
                mer4.BackColor = Color.Red
                kun3.BackColor = Color.Yellow
                kun2.BackColor = Color.Yellow
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 silahkan Jalan"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 22000
                hij2.BackColor = Color.FromArgb(0, 255, 0)
                mer1.BackColor = Color.Red
                mer3.BackColor = Color.Red
                mer4.BackColor = Color.Red
                kun3.BackColor = Color.FromArgb(64, 64, 0)
                kun2.BackColor = Color.FromArgb(64, 64, 0)
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "jalur 2 silahkan Jalan"
                lblT3.Text = "Jalur 3 belok kiri jalan terus"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 31000
                hij2.BackColor = Color.FromArgb(0, 64, 0)
                mer1.BackColor = Color.Red
                mer3.BackColor = Color.Red
                mer4.BackColor = Color.FromArgb(64, 0, 0)
                kun2.BackColor = Color.Yellow
                kun4.BackColor = Color.Yellow
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 belok kiri jalan terus"
                lblT4.Text = "Jalur 4 silahkan Jalan"
            Case 32000
                hij4.BackColor = Color.FromArgb(0, 255, 0)
                mer2.BackColor = Color.Red
                kun2.BackColor = Color.FromArgb(64, 64, 0)
                kun4.BackColor = Color.FromArgb(64, 64, 0)
                lblT1.Text = "Jalur 1 belok kiri jalan terus"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 belok kiri jalan terus"
                lblT4.Text = "Jalur 4 silahkan Jalan"
            Case 41000
                hij4.BackColor = Color.FromArgb(0, 64, 0)
                mer1.BackColor = Color.FromArgb(64, 0, 0)
                mer4.BackColor = Color.FromArgb(64, 0, 0)
                kun1.BackColor = Color.Yellow
                kun4.BackColor = Color.Yellow
                lblT1.Text = "Jalur 1 silahkan Jalan"
                lblT2.Text = "Jalur 2 belok kiri jalan terus"
                lblT3.Text = "Jalur 3 belok kiri jalan terus"
                lblT4.Text = "Jalur 4 belok kiri jalan terus"
            Case 42000
                kun4.BackColor = Color.FromArgb(64, 64, 0)
                time = 0
        End Select
    End Sub
End Class

2.   Soal yang kedua kita akan menghitung Luas dari atribut Panjang dan Lebar.
Coding :
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label4.Text = TextBox1.Text * TextBox2.Text
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        Label4.Text = ""
        TextBox1.Focus()
    End Sub


    Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
        Label1.ForeColor = Color.Red
    End Sub

    Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
        Label1.ForeColor = Color.Black
    End Sub

    Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
        Label2.ForeColor = Color.Red
    End Sub

    Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
        Label2.ForeColor = Color.Black
    End Sub
End Class


3.  Yang ketiga kita akan mencoba untuk membuat Kalkulator.
Coding :
Public Class Form2
    Dim aktif As String
    Private Sub txtpertama_GotFocus(sender As Object, e As EventArgs) Handles txtpertama.GotFocus
        aktif = "txtpertama"
    End Sub

    Private Sub txtkedua_GotFocus(sender As Object, e As EventArgs) Handles txtkedua.GotFocus
        aktif = "txtkedua"
    End Sub

    Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn1.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn1.Text
        End If
    End Sub

    Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn2.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn2.Text
        End If
    End Sub

    Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn3.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn3.Text
        End If
    End Sub

    Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn4.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn4.Text
        End If
    End Sub

    Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn5.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn5.Text
        End If
    End Sub

    Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn6.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn6.Text
        End If
    End Sub

    Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn7.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn7.Text
        End If
    End Sub

    Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn8.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn8.Text
        End If
    End Sub

    Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn9.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn9.Text
        End If
    End Sub

    Private Sub btn10_Click(sender As Object, e As EventArgs) Handles btn10.Click
        If aktif = "txtpertama" Then
            txtpertama.Text &= btn10.Text
        ElseIf aktif = "txtkedua" Then
            txtkedua.Text &= btn10.Text
        End If
    End Sub

    Private Sub btn11_Click(sender As Object, e As EventArgs) Handles btn11.Click
        If txtpertama.Text <> Nothing And txtkedua.Text <> Nothing Then
            lblkedua.Text = CInt(txtpertama.Text) + CInt(txtkedua.Text)
        End If
    End Sub

    Private Sub btn12_Click(sender As Object, e As EventArgs) Handles btn12.Click
        If txtpertama.Text <> Nothing And txtkedua.Text <> Nothing Then
            lblkedua.Text = CInt(txtpertama.Text) - CInt(txtkedua.Text)
        End If
    End Sub

    Private Sub btn13_Click(sender As Object, e As EventArgs) Handles btn13.Click
       If txtpertama.Text <> Nothing And txtkedua.Text <> Nothing Then
            lblkedua.Text = CInt(txtpertama.Text) * CInt(txtkedua.Text)
        End If
    End Sub

    Private Sub btn14_Click(sender As Object, e As EventArgs) Handles btn14.Click
        If txtpertama.Text <> Nothing And txtkedua.Text <> Nothing Then
            lblkedua.Text = CInt(txtpertama.Text) / CInt(txtkedua.Text)
        End If
    End Sub

    Private Sub btn15_Click(sender As Object, e As EventArgs) Handles btn15.Click
        txtpertama.Clear()
        txtkedua.Clear()
        lblkedua.Text = ""
    End Sub
End Class

Ok friends ...
Bagaimana ?
Cukup mengertikah ? atau masih bingung ?
Nantikan postingan saya yang lainnya ya friends, semoga post ini bermanfaat ....
:)


Tidak ada komentar:

Posting Komentar