MbahAgis

Validasi InputBox

Jul 25th, 2020 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.06 KB | None | 0 0
  1. Public Class Form1
  2.     Private Sub BtnInput_Click(sender As Object, e As EventArgs) Handles BtnInput.Click
  3.  
  4.         Dim Pesan As String = "Masukkan Angka"
  5.         Dim Judul As String = "Angka Valid 0-9"
  6.         Dim IsiDefault As Integer = 0
  7.  
  8.         'deklarasikan sebuah control InputBox
  9. 1:      Dim userInput As String = InputBox(Pesan, Judul, IsiDefault)
  10.  
  11.         If Len(userInput) = 0 Then 'jika InputBox kosong
  12.             TxtOutput.Text = IsiDefault
  13.         Else
  14.             'jika user menginput selain angka
  15.             If Not IsNumeric(userInput) Then
  16.                 'tampilkan DialogBox berisi pesan dan memperbolehkan user menutup dialogbox ini dengan menekan tombol Ok
  17.                 MsgBox("Inputan tidak valid, harap masukkan angka 0-9", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Perhatian")
  18.                 GoTo 1 'tampilkan ulang InputBox
  19.             Else
  20.                 'jika user menginput angka, maka tampilkan outputnya ke TextBox
  21.                 TxtOutput.Text = userInput
  22.             End If
  23.         End If
  24.  
  25.     End Sub
  26. End Class
  27.  
Advertisement
Add Comment
Please, Sign In to add comment