0% found this document useful (0 votes)
43 views5 pages

Form1 Object Eventargs

This document contains the code for a Visual Basic .NET Windows Forms application that performs unit conversion. The code handles loading the form, input validation for text boxes, conversion button clicks, and performing the calculation. It includes validation for numeric formats, enabling/disabling of buttons and text boxes based on input, and handling of the calculation and reset functions.

Uploaded by

Avissena Izhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

Form1 Object Eventargs

This document contains the code for a Visual Basic .NET Windows Forms application that performs unit conversion. The code handles loading the form, input validation for text boxes, conversion button clicks, and performing the calculation. It includes validation for numeric formats, enabling/disabling of buttons and text boxes based on input, and handling of the calculation and reset functions.

Uploaded by

Avissena Izhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Me.TextBox1.MaxLength = 10
Me.TextBox2.MaxLength = 10
Hasil.Text = ""
label4.Text = ""
label5.Text = ""
Hasil.Text = ""
CF.Enabled = False
KF.Enabled = False
TextBox2.Enabled = False
Hasil.Enabled = True
CA.Enabled = False
KA.Enabled = False
Hitung.Enabled = False
Re.Visible = False
Keluar.Visible = False
Satuanf.Visible = False
satuana.Visible = False
satuanp.Visible = False
End Sub

Private Sub TextBox1_Keypress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
CF.Enabled = True
KF.Enabled = False
TextBox2.Enabled = False
CA.Enabled = False
KA.Enabled = False
Hitung.Enabled = False
Re.Visible = False
Keluar.Visible = False

End Sub

Private Sub CF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles CF.Click
Keluar.Visible = False
Re.Visible = False
Dim cekf As Boolean
Dim karakter As Char
Dim titik As Integer

cekf = IsNumeric(TextBox1.Text)
titik = 0

For x = 1 To Len(TextBox1.Text)
karakter = Mid(TextBox1.Text, x, 1)
If karakter = "." Then
titik += 1
End If
If karakter = "," Then
titik += 1
End If
Next
If titik > 1 Then
cekf = False
End If

If cekf = True Then


label4.Text = TextBox1.Text
Satuanf.Visible = True
KF.Enabled = False
TextBox1.Enabled = False
MessageBox.Show("Format nilai F sudah benar!", "Message Box",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
TextBox2.Enabled = True
CF.Enabled = False

Else
TextBox1.Enabled = False
KF.Enabled = True
MessageBox.Show("Format nilai F salah!", "Message Box", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End If

End Sub

Private Sub KF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles KF.Click
Dim gaya As String
Dim konversi As String = ""
For X = 1 To Len(TextBox1.Text)
gaya = Mid(TextBox1.Text, X, 1)
If Asc(gaya) >= 46 And Asc(gaya) <= 57 Then
If Not (gaya = "." And konversi.Contains(".")) Then
konversi += gaya
End If
End If
Next

label4.Text = konversi
TextBox2.Enabled = True
CF.Enabled = False
KF.Enabled = False
Keluar.Visible = False
Re.Visible = False
Satuanf.Visible = True

End Sub

Private Sub TextBox2_keypress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Keluar.Visible = False
Re.Visible = False
KF.Enabled = False
CF.Enabled = False
TextBox1.Enabled = False
CA.Enabled = True
KA.Enabled = False
Hitung.Enabled = False
End Sub
Private Sub CA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CA.Click
Keluar.Visible = False
Re.Visible = False
Dim ceka As Boolean
Dim karakter As Char
Dim titik As Integer

ceka = IsNumeric(TextBox2.Text)
titik = 0

For x = 1 To Len(TextBox2.Text)
karakter = Mid(TextBox2.Text, x, 1)
If karakter = "." Then
titik += 1
End If
If karakter = "," Then
titik += 1
End If
Next
If titik > 1 Then
ceka = False
End If

If ceka = True Then


label5.Text = TextBox2.Text
satuana.Visible = True
KA.Enabled = False
Hitung.Enabled = True
MessageBox.Show("Format nilai A sudah benar!", "Message Box",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
TextBox2.Enabled = False
CA.Enabled = False

Else
TextBox1.Enabled = False
KA.Enabled = True
MessageBox.Show("Format nilai A salah!", "Message Box", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End If

End Sub

Private Sub KA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles KA.Click
Keluar.Visible = False
Re.Visible = False
CA.Enabled = False
Dim karakter2 As String
Dim hasila As String
hasila = ""
For x = 1 To Len(TextBox2.Text)
karakter2 = Mid(TextBox2.Text, x, 1)
If Asc(karakter2) >= 45 And Asc(karakter2) <= 57 Then
If Not (karakter2 = "." And hasila.Contains(".")) Then
If Not (karakter2 = "-" And x > 1) Then hasila += karakter2
End If
End If
Next
label5.Text = hasila
Hitung.Enabled = True
satuana.Visible = True
KA.Enabled = False
TextBox2.Enabled = False
End Sub

Private Sub Hitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Hitung.Click

Hasil.Text = Val(label4.Text) / Val(label5.Text)

Re.Visible = True
Re.Enabled = True
Hitung.Enabled = False
Keluar.Visible = True
satuanp.Visible = True

End Sub

Private Sub Re_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Re.Click
KF.Enabled = False
TextBox2.Enabled = False
CA.Enabled = False
KA.Enabled = False
label4.Text = ""
label5.Text = ""
Hasil.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
Hasil.Text = ""

TextBox1.Enabled = True
CF.Enabled = False
Re.Visible = False
Satuanf.Visible = False
satuana.Visible = False
Keluar.Visible = False
satuanp.Visible = False

End Sub

Private Sub Keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Keluar.Click
Dim ExitYN As System.Windows.Forms.DialogResult
ExitYN = MsgBox("Apakah Anda yakin ingin keluar?", MsgBoxStyle.YesNo, "Message
Box")
If ExitYN = MsgBoxResult.Yes Then
Close()
Else
End If
End Sub

End Class
𝜌

You might also like