TUTORIAL PEMBUATAN PROGRAM SELISIH
HARI
Buka aplikasi Visual Basic 2010, kemudian pilih New Project kemudian muncul Windows Form Application.
1.
Selanjutnya buat
project seperti yang di bawah ini.
Buat label untuk judul selanjutnya label buat buat Tanggal, Hari, Minggu,
Bulan, Tahun sebanyak 11 label untuk keseluruhan. Kemudian buat textbox sebanyak 8 dan pada Properties bagian ReadOnly diganti true supaya
tidak bisa diganti. Kemudian buat DateTimePicker
sebanyak 2 untuk tanggal awal dan tanggal akhir. Buat 2 Button untuk Refresh dan Exit.
Dengan
listingnya sebagai berikut.
Public Class Form1
Dim hari As Integer
Dim minggu As Integer
Dim bulan As Integer
Dim tahun As Integer
Private Sub
Button2_Click(sender As System.Object, e As
System.EventArgs) Handles
Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
End Sub
Private Sub
Button1_Click(sender As System.Object, e As
System.EventArgs) Handles
Button1.Click
Dim date1 As Date
Dim date2 As Date
Dim difference As TimeSpan
Dim
sisa_tahun As Integer
Dim selisih_bulan As Integer
Dim tahun As Integer
Dim selisih_minggu As
Integer
Dim selisih_hari As Integer
Dim weeks As Integer
Dim months As Integer
Dim sisa_months As Integer
Dim sisa_hari As Integer
Dim sisa_weeks As Integer
date1
= Convert.ToDateTime(DateTimePicker1.Value)
date2
= Convert.ToDateTime(DateTimePicker2.Value)
selisih_bulan = DateDiff("m",
date1, date2)
tahun
= selisih_bulan / 12
sisa_tahun = selisih_bulan Mod 12
selisih_hari = DateDiff("d",
date1, date2)
weeks
= selisih_hari / 7
sisa_weeks = selisih_hari Mod 7
selisih_minggu = DateDiff("ww",
date1, date2)
months = sisa_weeks / 30
sisa_months = sisa_weeks Mod 30
sisa_hari = selisih_minggu / 4 / 7
difference = date2 - date1
TextBox5.Text = FormatNumber(difference.TotalDays, 0)
TextBox5.Text = sisa_hari
TextBox6.Text = weeks
TextBox7.Text = months
TextBox7.Text = sisa_months
TextBox8.Text = tahun
hari
= DateDiff("d",
DateTimePicker1.Value, DateTimePicker2.Value)
TextBox1.Text = hari
minggu = hari / 7
TextBox2.Text = minggu
bulan
= DateDiff("m",
DateTimePicker1.Value, DateTimePicker2.Value)
TextBox3.Text = bulan
tahun
= bulan / 12
TextBox4.Text = tahun
End Sub
Private Sub
TextBox1_TextChanged(sender As System.Object, e As
System.EventArgs) Handles
TextBox1.TextChanged
If TextBox1.Text = ""
Then
TextBox1.Text = ""
Else
If TextBox1.Text < 0 Then
TextBox1.Text = TextBox1.Text * (-1)
Else
TextBox1.Text = TextBox1.Text
End If
End If
End Sub
Private Sub
TextBox2_TextChanged(sender As System.Object, e As
System.EventArgs) Handles
TextBox2.TextChanged
If TextBox2.Text = ""
Then
TextBox2.Text = ""
Else
If TextBox2.Text < 0 Then
TextBox2.Text = TextBox2.Text * (-1)
Else
TextBox2.Text = TextBox2.Text
End If
End If
End Sub
Private Sub
TextBox3_TextChanged(sender As System.Object, e As
System.EventArgs) Handles
TextBox3.TextChanged
If TextBox3.Text = ""
Then
TextBox3.Text = ""
Else
If TextBox3.Text < 0 Then
TextBox3.Text = TextBox3.Text * (-1)
Else
TextBox3.Text = TextBox3.Text
End If
End If
End Sub
Private Sub
TextBox4_TextChanged(sender As System.Object, e As
System.EventArgs) Handles
TextBox4.TextChanged
If TextBox4.Text = ""
Then
TextBox4.Text = ""
Else
If TextBox4.Text < 0 Then
TextBox4.Text = TextBox4.Text * (-1)
Else
TextBox4.Text = TextBox4.Text
End If
End If
End Sub
Private Sub
Button3_Click(sender As System.Object, e As
System.EventArgs) Handles
Button3.Click
MsgBox("Matur Nuwun")
Close()
End Sub
End Class
Selesai..