Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2006, 05:12 AM
Authorized User
 
Join Date: Mar 2006
Location: bedlington, northumberland, United Kingdom.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default age input sends out a cast error...HELP PLZ!!!

I am writing a piece of code which asks for the age of the user. I have validated the input to only allow numerics, however to validate being between 16 and 90years old on .leave of txtBox an error has been made saying :

   Cast from string "" to type 'Double' is not valid.

Does anyone have a clue how to fix this...I have read up on the error but unfortunatly, because I am just new to programing, the terminology is way above me...I only understand the literal basics...Sorry!
Please help me!!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Reply With Quote
  #2 (permalink)  
Old March 8th, 2006, 06:35 AM
Authorized User
 
Join Date: Mar 2006
Location: Aberdeen, Scotland, United Kingdom.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The variable you think has the age really has a blank string (""), and when you treat it as a number it produces the error. So...

1. Your not reading the appropriate variable
2. Your input is not reaching the correct place.

In any case, after you get the input you should first check if its not blank, like so:

if not strX = "" then
     'your code here...
end if

Can you send the code?

J
Reply With Quote
  #3 (permalink)  
Old March 8th, 2006, 07:20 AM
Authorized User
 
Join Date: Mar 2006
Location: bedlington, northumberland, United Kingdom.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you sooooo much for getting back to me. I have copied my code about an age below:

  'change the color of the text box if under 18 or over 90 years to draw attenion to the error
        If txtOrgAge.Text < 18 Or txtOrgAge.Text > 90 Then
            txtOrgAge.BackColor = System.Drawing.Color.Red
            MessageBox.Show("Sorry, you have to be between 18 and 90 to participate in this event", "MINIMUM AGE 18", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtOrgAge.Clear()
        End If

Can you see where I have gone wrong? Remeber that I have validated the txtbox to only input numeric data...is this the cause?
xxxxxxxxxxxxxxxxxxxxx

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
Receiving Error Msg:Unable to cast object of type cesemj ASP.NET 2.0 Basics 2 March 4th, 2008 02:18 PM
sends two messages instead of one?! shazza Biztalk 0 September 10th, 2007 03:19 PM
Submit button in the form sends an email in C# debjanib ASP.NET 2.0 Basics 2 July 17th, 2006 03:56 AM
sumbit button in the form sends an email debjanib ASP.NET 1.0 and 1.1 Professional 1 June 30th, 2006 03:55 PM
Error: "Specified cast not valid" on ItemDataBoun snejsnej ASP.NET 1.0 and 1.1 Professional 0 May 24th, 2006 05:36 PM



All times are GMT -4. The time now is 12:07 AM.


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