3 Replies - 2665 Views - Last Post: 08 September 2009 - 12:08 PM Rate Topic: -----

#1 Sollek   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Validating text & MessageBox.Show

Posted 08 September 2009 - 08:56 AM

Scenerio:
I'm working on a program to calculate Exp left until a title is available in game. I'm trying to validate that the user enters only numbers into the text box. Should s/he enter a letter I want my message box to show and then select the text that was incorrectly entered. My problem is in when the backspace key is hit it again shows the message. I believe it's in the TextChanged event but i'm not certain. Was hoping for guidance.

'Handles txtXP Box & Validates user input	 
'Converts over to a Double Number	 
'Provides Error Correction if anything other than #'s Used.	 
Private Sub txtXP_TextChanged(ByVal sender As System.Object, _								   ByVal e As System.EventArgs)
 _								   Handles txtXP.TextChanged		 
Dim Experience As Double		 
If Not IsNumeric(txtXP.Text) Then			 
MessageBox.Show("Please Enter Numbers Only, No Comma is Needed.")			 
Me.txtXP.Focus()			 
Me.txtXP.SelectAll()		 

Else			 
Experience = CDbl(Me.txtXP.Text)		 
End If	 
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Validating text & MessageBox.Show

#2 mark.bottomley   User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Validating text & MessageBox.Show

Posted 08 September 2009 - 10:14 AM

So, if you are not checking the text as entered, then either use mask edit fields to limit input, or clear the offending field completely by setting it to String.Empty
Was This Post Helpful? 0
  • +
  • -

#3 Sollek   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Validating text & MessageBox.Show

Posted 08 September 2009 - 11:06 AM

View Postmark.bottomley, on 8 Sep, 2009 - 09:14 AM, said:

So, if you are not checking the text as entered, then either use mask edit fields to limit input, or clear the offending field completely by setting it to String.Empty


Hmm sadly I'm not familiar with that feature yet.

I'm trying to validate text as entered yes, but only as numeric. I was taught to use IsNumeric for validation.

But when Delete or Backspace is used to clear text the message box again displays the error.

Me.txtXP.Text = ("") also pops the same message up. How would I implement string empty in it?

This post has been edited by Sollek: 08 September 2009 - 11:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 myork   User is offline

  • D.I.C Head

Reputation: 41
  • View blog
  • Posts: 129
  • Joined: 04-March 09

Re: Validating text & MessageBox.Show

Posted 08 September 2009 - 12:08 PM

How have you added txtXP.Text = ""? If you do it as follows, it should work:
If Not isNumeric(txtXP.Text) And txtXP.text <> "" Then '...

Mind you, that won't work if the user enters multiple characters and then deletes only one of them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1