APLIKASI PERKIRAAN CUACA DAN MENGHITUNG NILAI MIN & MAX DI VB 2010
Assalamualaikum.Wr.Wb
Pada kesempatan kali ini saya akan berbagi cara bagaimana membuat aplikasi Perikraan Cuaca & Mencari nilai Min & Max di vb 2010 .Untuk kali berbeda dengan yang sebelum sebelumnya karena menggunakan 2 Form yang pertama Form mencari nilai Min & Max yang kedua Form Perkiraan cuaca. Untuk kali ini saya menggunakan tambahan form yaitu menggunakan MDI Form sebagai Form utamanya. Sementara Untuk script nya sih sama saja dengan vb yang sebelum sebelumnya. Untuk lebih jelasnya berikut ini adalah langkah-langkahnya :1. Buka Visual Basic 2010 anda seperti gambar di bawah ini
2. Kemudian klik " New project " Seperti gambar di bawah ini
3. Setelah di klik maka akan mucul gambar di bawah ini kemudian klik " Windows Form Application "
4. Kemudian akan muncul form kosong seperti gambar di bawah ini
5. Setelah itu anda sorot ke arah kiri pada form ada atau cari " Toolbox" kemudian pilih " Button " , " TextBox ", " Label " seperti gambar di bawah ini
6. maka hasilnya akan muncul form seperti gambar di bawah ini
CATATAN : "Ganti semua properti seperti ListBox1, Button1 dan yang lainnya menjadi seperti gambar di bawah ini "
Objek | Text | Name |
ListBox | lstDisplay | |
Label1 | Angka Terkecil | lblSmallest |
Label2 | Angka Terbesar | lblHighest |
Label3 | Hasil | |
Button1 | Masukan Angka | btnInput |
Button2 | Tampilkan Angka Min dan Max | btnDisplay |
Button3 | Hapus | btnExit |
7. Untuk Form Min dan Max di bawah ini adalah scriptnya :
'NAMA : M.SAEPUL BURHAN
'NIM : TI 1210043
'JURUSAN : T.INFORMATIKA
Public Class MinMax
Const intMAX_SUBSCRIPT As Integer = 9 'The maximum subescript
Dim intNumbers(intMAX_SUBSCRIPT) As Integer 'array declaration
Dim intCount As Integer 'Loop count
Dim intHighest As Integer 'to hold the highest value
Dim intSmallest As Integer 'to hold the lowest value
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
lstDisplay.Items.Clear()
lblHighest.Text = String.Empty
lblSmallest.Text = String.Empty
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDisplay.SelectedIndexChanged
End Sub
Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click
'Masukan angka yang di input sampai 10
For Me.intCount = 0 To intMAX_SUBSCRIPT
intNumbers(intCount) = InputBox("Enter a number.")
Next
'Hapus Data yang ada di listbox
lstDisplay.Items.Clear()
'Menampilkan di LisBox
For Me.intCount = 0 To intMAX_SUBSCRIPT
lstDisplay.Items.Add(intNumbers(intCount))
Next
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
'get the first high value
intHighest = intNumbers(intMAX_SUBSCRIPT)
'search for the highest value.
For Me.intCount = 1 To (intNumbers.Length - 1)
If intNumbers(intCount) > intHighest Then
intHighest = intNumbers(intCount)
End If
Next
lblHighest.Text = "Angka Terbesar : " & intHighest.ToString
'get the first low value
intSmallest = intNumbers(intMAX_SUBSCRIPT)
'search for the lowest value
For Me.intCount = 0 To (intNumbers.Length - 1)
If intNumbers(intCount) < intSmallest Then
intSmallest = intNumbers(intCount)
End If
Next
lblSmallest.Text = "Angka Terkecil : " & intSmallest.ToString
End Sub
End Class
8. Buat form MDI seperti gambar di bawah ini
9. Berikut ini adalah script untuk Form MDI :
Imports System.Windows.Forms Public Class Form_Utama Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) End Sub Private Sub MencariNilaiMinDanMaxToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles MencariNilaiMinDanMaxToolStripMenuItem.Click MinMax.Show() End Sub Private Sub PerkiraanCuacaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PerkiraanCuacaToolStripMenuItem.Click Rainfall_Statistic.Show() End Sub Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click Close() End Sub End Class
CATATAN : "Ganti semua properti seperti ListBox1, Button1 dan yang lainnya menjadi seperti gambar di bawah ini "
Objek | Text | Name |
ListBox | lstRainfall | |
GroupBox | Hasil perkiraan cuaca | |
Label1 | … | lblAvgMonthly |
Label2 | … | lblTotalAnnual |
Label3 | … | lblMin |
Label4 | … | lblMax |
Button1 | Masukan Angka Perkiraan Cuaca | btnRainFall |
Button2 | Tampilkan Data Statistik | btnDisplay |
Button3 | Hapus | btnClear |
Button4 | Exit | btnExit |
Kode Di Sini Public Class Rainfall_Statistic Dim strMonths() As String = {"January", "February", "March", "April", _ "May", "June", "July", "August", "September", "October", "November", _ "December"} Dim intMonths(11) As Integer Dim intRain() As Integer Private Sub Rainfall_Statistic_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblAvgMonthly.Visible = False lblTotalAnnual.Visible = False lblMin.Visible = False lblMax.Visible = False End Sub Private Sub btnRainFall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRainFall.Click Dim intCount As Integer Dim intRain As Integer lstRainfall.Items.Add("Monthly Rainfall Input") lstRainfall.Items.Add("-----------------------------------") For intCount = 0 To 11 intRain = Val(InputBox("Enter the inches of rainfall for " & strMonths(intCount))) lstRainfall.Items.Add(strMonths(intCount) & " " & (intRain).ToString()) intMonths(intCount) = intRain Next intCount End Sub Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Dim intCount As Integer Dim intMaximum As Integer = intMonths(0) Dim intMinimum As Integer = intMonths(0) Dim dblAverage As Double Dim intTotal As Integer = 0 'calculate maximum For intCount = 1 To (intMonths.Length - 1) If intMonths(intCount) > intMaximum Then intMaximum = intMonths(intCount) End If Next intCount 'calculate(minimum) For intCount = 1 To (strMonths.Length - 1) If intMonths(intCount) < intMinimum Then intMinimum = strMonths(intCount) End If Next intCount 'calculate average For intCount = 1 To (strMonths.Length - 1) intTotal += intMonths(intCount) Next intCount 'use floating-point division to compute the average dblAverage = (intTotal / strMonths.Length) 'calculate total rainfall For intCount = 1 To (strMonths.Length - 1) intTotal += intMonths(intCount) Next intCount lblAvgMonthly.Visible = True lblTotalAnnual.Visible = True lblMin.Visible = True lblMax.Visible = True lblAvgMonthly.Text = "The average monthly rainfall was " & dblAverage lblTotalAnnual.Text = "The total annual rainfall was " & intTotal lblMin.Text = "The minimum monthly rainfall was " & intMinimum lblMax.Text = "The maximum monthly rainfall was " & intMaximum End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub End Class
13. Tekan F5 untuk menjalankan programnya maka hasilnya akan seperti gambar di bawah ini
Selamat mencoba ... (^_^)
幸運を... (^_^)
1 komentar:
Write komentarSangat membantu
Replypemuda-s.blogspot.com
EmoticonEmoticon