The first thing I'd suggest is using a MaskedTextBox. You can set the format to be only integers. Then handle the Validated event to check for divisibility by ten. The mod operator returns the remainder from a division. So if the quotient is 0 the dividend is exactly divisible by the divisor ...
i hope it could be help you in this matter. Private Sub TextBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Validated Dim number As Double = 0 If Double.TryParse(Me.TextBox1.Text, number) Then 'your code Else MessageBox.Show("Insert a number") Me.TextBox1.Clear() End If End Sub
The first thing I'd suggest is using a MaskedTextBox. You can set the format to be only integers. Then handle the Validated event to check for divisibility by ten. The mod operator returns the remainder from a division. So if the quotient is 0 the dividend is exactly divisible by the divisor
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MaskedTextBox1.ValidatingType = GetType(Integer)
MaskedTextBox1.Mask = "0000"
Private Sub MaskedTextBox1_Validated(sender As Object, e As EventArgs) Handles MaskedTextBox1.Validated
If Integer.Parse(MaskedTextBox1.Text) Mod 10 <> 0 Then
Windows.Forms.MessageBox.Show("Enter a multiple of 10 please.")
I have tried mulitple ways to incorporate the Mod with my validating whether a person actually enters an integer or not and I keep gettng a different error every time. I am just using the standard if/then statement.
Stop annoying users with unwanted Msgboxes saying: "He dummy! You typed a letter!" A Masked textbox might be ok, but I would rather use it for social security codes etc. BTW, you still have to validate for divisibility by 10. Try handling a KeyDown/KeyPress event. Here you can only allow digits and even test if the last digit entered was zero.
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If IsNumeric(TextBox1.Text) Then
If Integer.Parse(TextBox1.Text) Mod 100 <> 0 Then
Windows.Forms.MessageBox.Show("Enter a multiple of 100 please")
This is the code I have been basically working with so far. There are four textboxes that all require integers for the program to work. Plus they have to be divisible by Either 100, 50, or 20. This code I posted allows me to check for the integer being divisible by 100 but does not validate whether it's an integer or not. I appreciate the help I have gotten so far. It's helping me to reach my epiphony.
Thanks Chuchaykaw. That is a great help. I have used similar to that in this code:
Dim number As Double = 0
If Integer.Parse(TextBox1.Text) Mod 100 <> 0 And Double.TryParse(Me.TextBox1.Text, number) Then
Windows.Forms.MessageBox.Show("Please enter a valid number")
Else : TextBox2.Focus()
However, it keeps giving me a format error: Input string was not in a correct format.
Dim intvalue As Integer
If Not Integer.TryParse(TextBox1.Text, intvalue) OrElse intvalue Mod 100 <> 0 Then
MessageBox.Show("Please enter a Valid Number", "Message", MessageBoxButtons.OKCancel)
This is the code that works! Thanks for all the help. Just a simple if/then statement. This is an awesome forum for learning how to do vb.net!