Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2006, 09:13 PM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Small Help From a Noob!!!

Hey how is every one doing today?.
As for me I've been a stuck in what I know is extremly simple for most and well, becoming a small ache for me lol.

Well I've been learning vb.net on my own and so far its pretty good stuff, but I'm stuck in a simple validation process.

What I'm trying to do is example ( If there is a text box that requires a first name (which would be text) then everything is good, unless if it is Numbers or even special signs ($%&*) etc then display an error message) So far I've been able to do a simple IF statement which I can verify if the box is empty, but when it comes to the validation of numbers I just get stuck.

I know it may seem very simple to do this and I know it is because in other languages you can specify what is a number or character and etc, so far I just don't know how to do it in VB.

If some one can just simply point me to the right direction I would appreciated it big time!!.

Take care and thanks in advance for your comments.



 
Old April 4th, 2006, 06:57 AM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To keep everyone updated with my problem I tried to convert what is the first name text box to see if there is a numeric value, for example I would do

If CInt(txtFirstName.Text) Then
....
else etc etc etc

Anyhow this does work, but to a certain extend, because once I decide to insert text back into the same box, the program breaks off. So I'm still trying to find a way to solve this problem, If I do I will post it up on the forum, but until then if anyone out there please can let me know if there is a function or anything else that can solve this issue please
let me know.



 
Old April 4th, 2006, 10:00 AM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

**UPDATE AGAIN!! LOL**

Ok so far I ve been able to narrow it down a bit closer to my goal
this time I try to use a function which is IsNumeric

Here is the problem.

if IsNumeric(txtFirstName.Text)
.....
end if

Now this works to a certain degree, for example If I put a number then I get my messagebox error display "No numbers please" , but if I decide to do "John15" then everything goes through.

Keep in mind that in the first name text box I only need text to be inserted, not numbers or anything special(%&$#) etc etc

Also I tried this as well

If IsNumeric(txtFirstName.text.length) then
....
end if

The problem with this is that I get an error after I decide to put a character instead of a number.

If anyone reading out there can help me out I would surely appreciate it.

Thankyou.

P.S: If I find out the way I will post it, because I'm sure many of us face little bugs like these lol




 
Old April 4th, 2006, 10:39 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. i dont have any example around here, but your solution have to be something that includes regular expresion that only accept letters and other chars.

HTH

Gonzalo
 
Old April 4th, 2006, 11:31 PM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gbianchi
 hi there.. i dont have any example around here, but your solution have to be something that includes regular expresion that only accept letters and other chars.

HTH

Gonzalo
How can I do something like that?!?..I would think that the text box already accepts strings so under a certain circumstances if a user inserts a number within (Name field box) then I would be able to present a small messagebox display to the user "no numbers or special character etc".

But hey its a start at least lol.
Also anyone out there please don't be shy from your opinion as long as its helpful i would appreciate it :)

 
Old April 5th, 2006, 05:05 PM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

** Update 2.0 lol **

To keep things a bit more simple I will include the first name text box code and therefore it would make it a bit easier for those who are willing to help with this issue

//////////////////////

If IsNumeric(txtFirstName.Text.ToString) Then
            MessageBox.Show("No numbers within the First Name Text Box!!", "Error", MessageBoxButtons.OK _
            , MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            txtFirstName.Focus()

End If

 
Old April 5th, 2006, 06:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Put this in the KeyPress event of the textbox that you want to validate:

If e.KeyChar.IsNumber(e.KeyChar) Then
     e.Handled = True
End If
 
Old April 5th, 2006, 08:19 PM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by katsarosj
 Put this in the KeyPress event of the textbox that you want to validate:

If e.KeyChar.IsNumber(e.KeyChar) Then
     e.Handled = True
End If
Wow this definetly works, because once the user even dares lol to put a number within the textbox the event triggers and stops him/her from inserting a number or even a mix of numbers with character like "John15" etc from being inserted.

Thankyou so much for your help , believe me I'm sure you help this noob out as well as many others who might of had this problem in their own little programs :)

 
Old April 7th, 2006, 07:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No problem. You can also use this method to check for special characters ($, %, etc.)

J
 
Old April 7th, 2006, 10:30 PM
Authorized User
 
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by katsarosj
 No problem. You can also use this method to check for special characters ($, %, etc.)

J
yeah I did use the method for that as well as for letters. It is a pretty useful method because everything gets authenticated at the textbox itself , instead of waiting for a button to execute the method when a user presses it.

Thankyou for helping me out and as well as any other person who might of had the same problem with their own program.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help a noob wilbo BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 22nd, 2008 11:54 AM
noob question mattl Java Basics 1 August 27th, 2007 11:28 PM
Noob Needs Help -XM- BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 3 June 28th, 2007 04:53 PM
Noob needs help. dangel75 BOOK: Beginning ASP.NET 1.0 3 March 19th, 2006 06:38 PM
Complete Noob KnowTheForce Beginning VB 6 3 December 19th, 2005 10:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.