Rabu, 08 Juni 2011

Coding Visual Basic Bagan Tempat Duduk Pesawat Terbang

Public Class Tempat duduk pesawat terbang
Dim item As Integer
Public baris As Integer, bangku, kodebangku As Char
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LstTempatDuduk.Items.Add(" A B C" & vbTab & "D E F")
For Me.item = 1 To 15
LstTempatDuduk.Items.Add("" & Space(4) & "." & Space(4) & "." & Space(4) & "." & Space(14) & "." & Space(4) & "." & Space(4) & ".")
Next
lblterisi.Text = "0"
lblkosong.Text = "90"
lblreg.Text = "0"
lblrdkal.Text = "0"
lblveg.Text = "0"
End Sub
Private Sub LstTempatDuduk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LstTempatDuduk.Click
If LstTempatDuduk.SelectedIndex = 0 Then
TxtBaris.Clear()
TxtA.Clear()
TxtC.Clear()
TxtD.Clear()
TxtE.Clear()
TxtF.Clear()
Exit Sub
End If
baris = LstTempatDuduk.SelectedIndex.ToString
TxtBaris.Text = baris
TxtA.Text = GetChar(LstTempatDuduk.SelectedItem, 5)
TxtB.Text = GetChar(LstTempatDuduk.SelectedItem, 10)
TxtC.Text = GetChar(LstTempatDuduk.SelectedItem, 15)
TxtD.Text = GetChar(LstTempatDuduk.SelectedItem, 30)
TxtE.Text = GetChar(LstTempatDuduk.SelectedItem, 35)
TxtF.Text = GetChar(LstTempatDuduk.SelectedItem, 40)
End Sub
Private Sub TxtA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtA.Click
If TxtA.Text = "" Then Exit Sub
bangku = "A"
kodebangku = TxtA.Text
Form2.Show()
End Sub


Private Sub TxtB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtB.Click
If TxtB.Text = "" Then Exit Sub
bangku = "B"
kodebangku = TxtB.Text
Form2.Show()
End Sub

Private Sub TxtC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtC.Click
If TxtC.Text = "" Then Exit Sub
bangku = "C"
kodebangku = TxtC.Text
Form2.Show()
End Sub
Private Sub TxtD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtD.Click
If TxtD.Text = "" Then Exit Sub
bangku = "D"
kodebangku = TxtD.Text
Form2.Show()
End Sub
Private Sub TxtE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtE.Click
If TxtE.Text = "" Then Exit Sub
bangku = "E"
kodebangku = TxtE.Text
Form2.Show()
End Sub
Private Sub TxtF_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TxtF.Click
If TxtF.Text = "" Then Exit Sub
bangku = "F"
kodebangku = TxtF.Text
Form2.Show()
End Sub
End Class

Public Class Form2
Dim bkntmptduduk, baris As Integer
Dim brstmptduduk As String
Dim terisi, jlhR, jlhL, jlhV As Integer
Dim kosong As Integer = 0
Sub hitung()
Dim no As Integer, huruf As Char, bangku As String
With Form1
For Me.baris = 1 To 15
.LstTempatDuduk.SetSelected(baris, True)
bangku = .LstTempatDuduk.SelectedItem
For no = 1 To 40
huruf = bangku.Substring(no - 1, 1)
Select Case huruf
Case "." : kosong += 1
Case "R" : jlhR += 1
Case "L" : jlhL += 1
Case "V" : jlhV += 1
End Select
Next
Next
.lblkosong.Text = kosong
.lblterisi.Text = 90 - kosong
.lblreg.Text = jlhR
.lblrdkal.Text = jlhL
.lblveg.Text = jlhV
.LstTempatDuduk.SetSelected(0, True)
End With
End Sub

Sub kosongkan()
With Form1
.TxtBaris.Clear()
.TxtA.Clear()
.TxtB.Clear()
.TxtC.Clear()
.TxtD.Clear()
.TxtE.Clear()
.TxtD.Clear()
.TxtF.Clear()
End With
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Posisi Tempat Duduk" & Space(4) & Form1.baris & Form1.bangku
Select Case Form1.bangku
Case "A" : bkntmptduduk = 5
Case "B" : bkntmptduduk = 10
Case "C" : bkntmptduduk = 15
Case "D" : bkntmptduduk = 30
Case "E" : bkntmptduduk = 35
Case "F" : bkntmptduduk = 40
End Select
Select Case Form1.kodebangku
Case "." : RdbBel.Checked = True
Case "R" : RdbReg.Checked = True
Case "L" : RdbRen.Checked = True
Case "V" : RdbVeg.Checked = True
End Select
End Sub

Private Sub RdbReg_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RdbReg.MouseClick
brstmptduduk = Microsoft.VisualBasic.Left(Form1.LstTempatDuduk.SelectedItem, bkntmptduduk - 1) & Replace(Form1.LstTempatDuduk.SelectedItem, Form1.kodebangku, "R", bkntmptduduk, 1) & ""
Form1.LstTempatDuduk.Items.RemoveAt(Form1.baris)
Form1.LstTempatDuduk.Items.Insert(Form1.baris, brstmptduduk)
Call kosongkan()
Me.Close()
Call hitung()
End Sub

Private Sub RdbBel_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RdbBel.MouseClick
brstmptduduk = Microsoft.VisualBasic.Left(Form1.LstTempatDuduk.SelectedItem, bkntmptduduk - 1) & Replace(Form1.LstTempatDuduk.SelectedItem, Form1.kodebangku, ".", bkntmptduduk, 1) & ""
Form1.LstTempatDuduk.Items.RemoveAt(Form1.baris)
Form1.LstTempatDuduk.Items.Insert(Form1.baris, brstmptduduk)
Call kosongkan()
Me.Close()
Call hitung()
End Sub

Private Sub RdbRen_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RdbRen.MouseClick
brstmptduduk = Microsoft.VisualBasic.Left(Form1.LstTempatDuduk.SelectedItem, bkntmptduduk - 1) & Replace(Form1.LstTempatDuduk.SelectedItem, Form1.kodebangku, "L", bkntmptduduk, 1) & ""
Form1.LstTempatDuduk.Items.RemoveAt(Form1.baris)
Form1.LstTempatDuduk.Items.Insert(Form1.baris, brstmptduduk)
Call kosongkan()
Me.Close()
Call hitung()
End Sub

Private Sub RdbVeg_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RdbVeg.CheckedChanged

End Sub
Private Sub RdbVeg_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RdbVeg.MouseClick
brstmptduduk = Microsoft.VisualBasic.Left(Form1.LstTempatDuduk.SelectedItem, bkntmptduduk - 1) & Replace(Form1.LstTempatDuduk.SelectedItem, Form1.kodebangku, "V", bkntmptduduk, 1) & ""
Form1.LstTempatDuduk.Items.RemoveAt(Form1.baris)
Form1.LstTempatDuduk.Items.Insert(Form1.baris, brstmptduduk)
Call kosongkan()
Me.Close()
Call hitung()
End Sub
End Class

Tidak ada komentar:

Posting Komentar

Berkomentarlah yang baik..