Click here to Skip to main content
15,919,500 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionValidation of the date and number [SOLVED] Pin
Frauenarzt7-Oct-09 5:58
Frauenarzt7-Oct-09 5:58 
AnswerRe: Validation of the date and number Pin
EliottA7-Oct-09 6:08
EliottA7-Oct-09 6:08 
GeneralRe: Validation of the date and number Pin
Frauenarzt7-Oct-09 6:27
Frauenarzt7-Oct-09 6:27 
GeneralRe: Validation of the date and number Pin
Henry Minute7-Oct-09 7:18
Henry Minute7-Oct-09 7:18 
GeneralRe: Validation of the date and number Pin
Frauenarzt7-Oct-09 7:32
Frauenarzt7-Oct-09 7:32 
GeneralRe: Validation of the date and number Pin
Henry Minute7-Oct-09 7:38
Henry Minute7-Oct-09 7:38 
GeneralRe: Validation of the date and number [modified] Pin
Frauenarzt7-Oct-09 7:47
Frauenarzt7-Oct-09 7:47 
GeneralRe: Validation of the date and number Pin
Henry Minute7-Oct-09 8:33
Henry Minute7-Oct-09 8:33 
Yup your 'added:' is correct.

Readline() reads a series of characters and returns them as a String. Your code works because, behind the scenes, the VB compiler 'sees' that you want an int and does the casting for you. Just to confirm this for your own satisfaction, run the code and enter '22f', after a bit you should get an exception message saying 'The cast from string to int was unsuccessful.', or similar. Now you haven't done any casting, so it must have been done for you. (FYI: your code won't even compile in C#. Another reason not to do it this way, just in case you have to change language for some reason. Smile | :) )
In C# your code is almost identical:
int int_number = 0;

System.Console.WriteLine("Enter number");
int_number = System.Console.ReadLine(); // <============= COMPILER FAILS HERE 'Cannot convert String to Int'

System.Console.WriteLine(int_number);


Anyway, if you always treat the value from a ReadLine() as a string, you won't get any run-time errors, regardless of what the user enters. You can then attempt the conversion yourself, in a way that you can control. Using the TryParse() methods of the various Types is about the most easily controlled way of doing it.

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

GeneralRe: Validation of the date and number [modified] Pin
Frauenarzt7-Oct-09 9:18
Frauenarzt7-Oct-09 9:18 
GeneralRe: Validation of the date and number Pin
EliottA7-Oct-09 9:22
EliottA7-Oct-09 9:22 
GeneralRe: Validation of the date and number Pin
Ian Shlasko7-Oct-09 9:38
Ian Shlasko7-Oct-09 9:38 
GeneralRe: Validation of the date and number Pin
Henry Minute7-Oct-09 10:21
Henry Minute7-Oct-09 10:21 
QuestionConnecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 5:08
Garth Geoghan7-Oct-09 5:08 
AnswerRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
EliottA7-Oct-09 5:11
EliottA7-Oct-09 5:11 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 5:33
Garth Geoghan7-Oct-09 5:33 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 7:12
Garth Geoghan7-Oct-09 7:12 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
EliottA7-Oct-09 7:19
EliottA7-Oct-09 7:19 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 7:23
Garth Geoghan7-Oct-09 7:23 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 7:27
Garth Geoghan7-Oct-09 7:27 
AnswerRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Dave Kreskowiak7-Oct-09 5:15
mveDave Kreskowiak7-Oct-09 5:15 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 5:29
Garth Geoghan7-Oct-09 5:29 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Dave Kreskowiak7-Oct-09 6:35
mveDave Kreskowiak7-Oct-09 6:35 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 6:38
Garth Geoghan7-Oct-09 6:38 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Garth Geoghan7-Oct-09 6:42
Garth Geoghan7-Oct-09 6:42 
GeneralRe: Connecting VB2008 Express to SQL Server 2008 Developer Pin
Dave Kreskowiak7-Oct-09 9:08
mveDave Kreskowiak7-Oct-09 9:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.