Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 18th, 2008, 10:18 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default TextBox entry validation

Hello please help,
I am beginning to learn VB 2005 in my retirement as a hobby.
I have a small form with a textbox and OK button. I want to enter a date in the text box and on clicking OK the input has to be validated as a date. If invalid entry of date to be activated. I am unable to use do loop, as it turns out in a never ending loop. Please help with a bit of coding.
Thillai

Reply With Quote
The Following User Says Thank You to thillai For This Useful Post:
  #2 (permalink)  
Old February 18th, 2008, 10:25 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

If this is a windows application you can use the MaskedTextBox to only allow for dates: http://msdn2.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask(VS.80).asp x

If this is a webform you can use a RegularExpressionValidator to verify that the data matches XYZ date pattern.

hth.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old February 18th, 2008, 10:41 AM
Registered User
 
Join Date: Feb 2008
Location: london, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Thillai

I'm also new to 2005 and .NET but I've just come across the ISdate function that returns a logical indicating if the given value can be converted to a Date.

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vbalr/html/b3141515-98e3-4891-b2dc-6b04ac669af9.htm

Hope this is of Help
Zishan

Reply With Quote
  #4 (permalink)  
Old February 18th, 2008, 10:52 AM
Registered User
 
Join Date: Feb 2008
Location: london, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Option Strict On
Public Class Form1

    Private Sub txtValidate_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles txtValidate.Click

        Dim DateOK As Boolean

        DateOK = IsDate(txtDate.Text)

        MessageBox.Show(DateOK.ToString)

    End Sub
End Class

Reply With Quote
  #5 (permalink)  
Old February 19th, 2008, 01:25 PM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi all
Thanks for all the replies. But I may have not made it very clear. I am able to get the date and test it if it is valid date. If valid I am accepting it as a date of birth or whatever. If invalid date I want to be able go back and get the user to input again. This is where I have trouble. I coded a loop (Do While Loo) and it goes into an never ending loop.
How do I go back and allow reenter until a valid date has been entered. Please help, Thanks again to all.
Thillai

Reply With Quote
  #6 (permalink)  
Old February 19th, 2008, 02:26 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When validation fails, set the focus to the textbox, and exit the validating sub.
You can post a MessageBox first to alert the user as to why you are sending them back to the box.

It is not a very friendly thing to do to delete the contents when the contents are wrong, but of course you could. If that triggers a _Change event, and that's a problem, do this. Create a global boolean. At the top of the _Change event routine add If MyBoolean = True Then Exit Sub. In the validation routine, before deleting the contents, set MyBoolean to True. Empty the contents, then set the Boolean back to false.

You can sent the focus back to the cantrol, set the controls SelectionStart to 0 or 1 (I fergit), and set the SelectionLength to Textbox.Text.Length(). (The actual terms might be a little differetn, but this should at least convey the idea...)
Reply With Quote
  #7 (permalink)  
Old February 20th, 2008, 07:23 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi all
Here I am again saying a big thank you to all of you who replied for my problem. I used a combination of MaskedTextBox and IsDate Validation and setting focus after failed validation for reentry and it works very well, better than my expectation!
Thanks again friends for all your help and looking forward to write to you all again when in difficulty.
Thillai

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date entry textbox as / / adamusufi SQL Server 2000 5 February 22nd, 2009 12:23 AM
Enter as a valid entry in a textbox (VB) Grimgore BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 2 February 9th, 2009 04:37 PM
Textbox validation rhd110 .NET Framework 2.0 1 March 28th, 2007 02:49 PM
textbox validation in c# dhol C# 3 July 22nd, 2005 05:57 AM
TextBox Validation Brettvan1 VB.NET 2002/2003 Basics 1 June 23rd, 2005 08:58 AM



All times are GMT -4. The time now is 09:41 PM.


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