Rabu, 13 April 2016

Contoh program yang dibuat adalah program untuk mengkonversi suhu, berikut ini adalah bentuk tampilan program yang saya buat :




Untuk membentuk tampilan program seperti diatas, objek-objek yang diperlukan adalah :
  1. Satu buah form
  2. Tiga buah Group Box (untuk 3 jenis konversi)
  3. Lima buah Button (3 button untuk tombol Convert, 2 Button untuk tombol Clear dan Exit.
  4. Enam buah Label
  5. Enam buah TextBox


Berikut ini adalah method-method yang diberikan untuk menjalankan program diatas :

Deklarasi :
Public Class konversi
        Public celcius, fahrenheit As Single
        Public Function celfah() As Double
            Return 1.8 * celcius + 32
        End Function
        Public Function celream() As Double
            Return celcius * 0.8
        End Function
        Public Function fahcel() As Double
            Return (fahrenheit - 32) / 1.8
        End Function
End Class

Form Load :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Welcome To The Temperature Conversion Program !!", vbInformation, "Warning !!!")
End Sub


Button Convert (GroupBox 1):
Private Sub convert1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convert1.Click
Dim objcelfah As New konversi
With objcelfah
.celcius = textcel1.Text
textfah1.Text = .celfah
End With
textcel1.Enabled = False
convert1.Enabled = False
buttonclear.Enabled = True
End Sub


Button Convert (GroupBox 2):
Private Sub convert2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convert2.Click
        Dim objcelream As New konversi
        With objcelream
            .celcius = textcel2.Text
            textreamur.Text = .celream
        End With
        textcel2.Enabled = False
        convert2.Enabled = False
        buttonclear.Enabled = True
End Sub


Button Convert (GroupBox 3):
Private Sub convert3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convert3.Click
        Dim objfahcel As New konversi
        With objfahcel
            .fahrenheit = textfah3.Text
            textcel3.Text = .fahcel
        End With
        textfah3.Enabled = False
        convert3.Enabled = False
        buttonclear.Enabled = True
End Sub


Button Clear:
Private Sub buttonclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonclear.Click
        textcel1.Text = ""
        textcel2.Text = ""
        textcel3.Text = ""
        textfah1.Text = ""
        textfah3.Text = ""
        textreamur.Text = ""

        convert1.Enabled = True
        convert2.Enabled = True
        convert3.Enabled = True
        buttonclear.Enabled = False

        textcel1.Enabled = True
        textcel2.Enabled = True
        textfah3.Enabled = True
        textcel1.Focus()
End Sub


Button Exit:
Private Sub buttonexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonexit.Click
If MsgBox("Are You Sure Want to Quit ??", vbOKCancel, "Warning !!!") = MsgBoxResult.Ok Then
            Me.Close()
        Else
            Me.Show()
            textcel1.Focus()
        End If

End Sub


0 komentar:

Clock

Gunadarma University

Popular Posts

Diberdayakan oleh Blogger.