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

Visual Basic Form Input Validation

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)
5 views5 pages

Visual Basic Form Input Validation

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

Public Class Form1

Private Sub Form1_Load(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
[Link] = 10
[Link] = 10
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = False
[Link] = False
[Link] = False
[Link] = True
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
End Sub

Private Sub TextBox1_Keypress(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] = True
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False

End Sub

Private Sub CF_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
[Link] = False
[Link] = False
Dim cekf As Boolean
Dim karakter As Char
Dim titik As Integer

cekf = IsNumeric([Link])
titik = 0

For x = 1 To Len([Link])
karakter = Mid([Link], 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


[Link] = [Link]
[Link] = True
[Link] = False
[Link] = False
[Link]("Format nilai F sudah benar!", "Message Box",
[Link], [Link])
[Link] = True
[Link] = False

Else
[Link] = False
[Link] = True
[Link]("Format nilai F salah!", "Message Box", [Link],
[Link])
End If

End Sub

Private Sub KF_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
Dim gaya As String
Dim konversi As String = ""
For X = 1 To Len([Link])
gaya = Mid([Link], X, 1)
If Asc(gaya) >= 46 And Asc(gaya) <= 57 Then
If Not (gaya = "." And [Link](".")) Then
konversi += gaya
End If
End If
Next

[Link] = konversi
[Link] = True
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = True

End Sub

Private Sub TextBox2_keypress(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = True
[Link] = False
[Link] = False
End Sub
Private Sub CA_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = False
[Link] = False
Dim ceka As Boolean
Dim karakter As Char
Dim titik As Integer

ceka = IsNumeric([Link])
titik = 0

For x = 1 To Len([Link])
karakter = Mid([Link], 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


[Link] = [Link]
[Link] = True
[Link] = False
[Link] = True
[Link]("Format nilai A sudah benar!", "Message Box",
[Link], [Link])
[Link] = False
[Link] = False

Else
[Link] = False
[Link] = True
[Link]("Format nilai A salah!", "Message Box", [Link],
[Link])
End If

End Sub

Private Sub KA_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
[Link] = False
[Link] = False
[Link] = False
Dim karakter2 As String
Dim hasila As String
hasila = ""
For x = 1 To Len([Link])
karakter2 = Mid([Link], x, 1)
If Asc(karakter2) >= 45 And Asc(karakter2) <= 57 Then
If Not (karakter2 = "." And [Link](".")) Then
If Not (karakter2 = "-" And x > 1) Then hasila += karakter2
End If
End If
Next
[Link] = hasila
[Link] = True
[Link] = True
[Link] = False
[Link] = False
End Sub

Private Sub Hitung_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]

[Link] = Val([Link]) / Val([Link])

[Link] = True
[Link] = True
[Link] = False
[Link] = True
[Link] = True

End Sub

Private Sub Re_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""

[Link] = True
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False

End Sub

Private Sub Keluar_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
Dim ExitYN As [Link]
ExitYN = MsgBox("Apakah Anda yakin ingin keluar?", [Link], "Message
Box")
If ExitYN = [Link] Then
Close()
Else
End If
End Sub

End Class
𝜌

You might also like