Selection in Visual basic.Net

Hello everybody, I am back to try to make application in Visual Basic.Net With If..Then..Else Selection. Well, Actually in visual Basic.Net there are so many kinds of Selection like If..Then..ELse, If..Then..ElseIf,Iif, and Select..Case. But for this occasion, we will make an application using If..Then..Else selection, here we are

1. Design the form like at picture above
2. Set the properties like in the previous program, for example for textbox1 named by txtName, for button of Hitung named by btnHitung, etc.
3. type the source code bellow :
Public Class Form1
Inherits System.Windows.Forms.FormConst jamNormal = 40
Const upahLembur = 10000
Dim nik As String
Dim nama As String
Dim gol As Char
Dim jjk As Integer
Dim upahPerJam As Double
Dim lembur As Double
Dim upahTotal As Double

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents txtNIk As System.Windows.Forms.TextBox
Friend WithEvents txtNama As System.Windows.Forms.TextBox
Friend WithEvents txtGol As System.Windows.Forms.TextBox
Friend WithEvents txtJjk As System.Windows.Forms.TextBox
Friend WithEvents btnHitung As System.Windows.Forms.Button
Friend WithEvents btnKeluar As System.Windows.Forms.Button
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents txtGaji As System.Windows.Forms.TextBox
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.txtNIk = New System.Windows.Forms.TextBox
Me.txtNama = New System.Windows.Forms.TextBox
Me.txtGol = New System.Windows.Forms.TextBox
Me.txtJjk = New System.Windows.Forms.TextBox
Me.btnHitung = New System.Windows.Forms.Button
Me.btnKeluar = New System.Windows.Forms.Button
Me.Label6 = New System.Windows.Forms.Label
Me.txtGaji = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(8, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(132, 22)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Data Penggajian"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 1
Me.Label2.Text = "NIK"
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.0!)
Me.Label3.Location = New System.Drawing.Point(8, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 16)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Nama"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 112)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(64, 16)
Me.Label4.TabIndex = 3
Me.Label4.Text = "Gol."
'
'Label5
'
Me.Label5.AutoSize = True
Me.Label5.Location = New System.Drawing.Point(8, 136)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(90, 16)
Me.Label5.TabIndex = 4
Me.Label5.Text = "Jumlah jam kerja"
'
'txtNIk
'
Me.txtNIk.Location = New System.Drawing.Point(120, 56)
Me.txtNIk.Name = "txtNIk"
Me.txtNIk.Size = New System.Drawing.Size(120, 20)
Me.txtNIk.TabIndex = 5
Me.txtNIk.Text = ""
'
'txtNama
'
Me.txtNama.Location = New System.Drawing.Point(120, 80)
Me.txtNama.Name = "txtNama"
Me.txtNama.Size = New System.Drawing.Size(184, 20)
Me.txtNama.TabIndex = 6
Me.txtNama.Text = ""
'
'txtGol
'
Me.txtGol.Location = New System.Drawing.Point(120, 104)
Me.txtGol.Name = "txtGol"
Me.txtGol.Size = New System.Drawing.Size(120, 20)
Me.txtGol.TabIndex = 7
Me.txtGol.Text = ""
'
'txtJjk
'
Me.txtJjk.Location = New System.Drawing.Point(120, 128)
Me.txtJjk.Name = "txtJjk"
Me.txtJjk.Size = New System.Drawing.Size(120, 20)
Me.txtJjk.TabIndex = 8
Me.txtJjk.Text = ""
'
'btnHitung
'
Me.btnHitung.Location = New System.Drawing.Point(16, 168)
Me.btnHitung.Name = "btnHitung"
Me.btnHitung.Size = New System.Drawing.Size(96, 32)
Me.btnHitung.TabIndex = 9
Me.btnHitung.Text = "&Hitung gaji"
'
'btnKeluar
'
Me.btnKeluar.Location = New System.Drawing.Point(112, 168)
Me.btnKeluar.Name = "btnKeluar"
Me.btnKeluar.Size = New System.Drawing.Size(96, 32)
Me.btnKeluar.TabIndex = 10
Me.btnKeluar.Text = "&Keluar"
'
'Label6
'
Me.Label6.AutoSize = True
Me.Label6.Location = New System.Drawing.Point(8, 216)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(114, 16)
Me.Label6.TabIndex = 11
Me.Label6.Text = "Total Gaji Per Minggu"
'
'txtGaji
'
Me.txtGaji.Location = New System.Drawing.Point(120, 216)
Me.txtGaji.Name = "txtGaji"
Me.txtGaji.Size = New System.Drawing.Size(120, 20)
Me.txtGaji.TabIndex = 12
Me.txtGaji.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.ClientSize = New System.Drawing.Size(328, 262)
Me.Controls.Add(Me.txtGaji)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.btnKeluar)
Me.Controls.Add(Me.btnHitung)
Me.Controls.Add(Me.txtJjk)
Me.Controls.Add(Me.txtGol)
Me.Controls.Add(Me.txtNama)
Me.Controls.Add(Me.txtNIk)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Seleksi Dengan If..Else"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitung.Click
nik = txtNIk.Text
nama = txtNama.Text
gol = txtGol.Text
jjk = txtJjk.Text
If gol = "A" Then
upahPerJam = 6500
Else
If gol = "B" Then
upahPerJam = 7500
Else
If gol = "C" Then
upahPerJam = 8500
End If
End If
End If
If jjk <= jamNormal Then upahTotal = jjk * upahPerJam Else lembur = jjk - jamNormal upahTotal = jamNormal * upahPerJam + lembur * upahLembur End If txtGaji.Text = upahTotal End Sub Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click End End Sub End Class Remember, we shouldn't write all source code above, Visual Basic.Net is Object oriented programming, that's why there is inheritance. We just write about global declarations ; Const UpahLembur = 10000, and another statement of btnHItung_click, Private sub btnHItung_click ...
Well..to make us not confuse, just Try it :).
Created By Ader.

Popular posts from this blog

Introduction to Use Case Diagram - Case study: Facebook

Kenapa tidak berkurban?

Sequential Search