PC Review


Reply
Thread Tools Rate Thread

Checking for Valid Datatype

 
 
Anonymous
Guest
Posts: n/a
 
      7th Jan 2004
This is a pretty dumb question but I can't seem to find
answer.

How do you check to see if a datatype of a variable is
correct? Eg in Visual Basic:

Dim datevar
datevar= "1a/2/2004"

If IsDate(datevar) <> true then
msgbox "The value in variable 'datevar' is not a date."
End if

Thanks.

 
Reply With Quote
 
 
 
 
Manoj G [MVP]
Guest
Posts: n/a
 
      7th Jan 2004
Use Typeof. For Eg

If TypeOf dateVar Is DateTime Then
'Your code
End If

--
HTH,
Manoj G [.NET MVP]
http://www15.brinkster.com/manoj4dotnet

"Anonymous" <(E-Mail Removed)> wrote in message
news:055b01c3d4b5$5a361a10$(E-Mail Removed)...
> This is a pretty dumb question but I can't seem to find
> answer.
>
> How do you check to see if a datatype of a variable is
> correct? Eg in Visual Basic:
>
> Dim datevar
> datevar= "1a/2/2004"
>
> If IsDate(datevar) <> true then
> msgbox "The value in variable 'datevar' is not a date."
> End if
>
> Thanks.
>



 
Reply With Quote
 
Anonymous
Guest
Posts: n/a
 
      7th Jan 2004
That's all it is? I feel dumb indeed!! Now you know why I
had Anonymous as my name!! )

Thanks a lot for info.
>-----Original Message-----
>Use Typeof. For Eg
>
>If TypeOf dateVar Is DateTime Then
> 'Your code
>End If
>
>--
>HTH,
>Manoj G [.NET MVP]
>http://www15.brinkster.com/manoj4dotnet
>
>"Anonymous" <(E-Mail Removed)> wrote

in message
>news:055b01c3d4b5$5a361a10$(E-Mail Removed)...
>> This is a pretty dumb question but I can't seem to find
>> answer.
>>
>> How do you check to see if a datatype of a variable is
>> correct? Eg in Visual Basic:
>>
>> Dim datevar
>> datevar= "1a/2/2004"
>>
>> If IsDate(datevar) <> true then
>> msgbox "The value in variable 'datevar' is not a date."
>> End if
>>
>> Thanks.
>>

>
>
>.
>

 
Reply With Quote
 
Anonymous
Guest
Posts: n/a
 
      7th Jan 2004
Hi, Manoj. I tried your code in C# but it won't work.
Here is what I tried to do but it kept erroring out.

if typeof(txtStartDate.Text)is System.DateTime

{
this.lblStatus.Text = "Start Date must be a date value.";
return;
}

Do I have to assign txtStartDate to a variable? How would
you do it? Thanks for info.

>-----Original Message-----
>That's all it is? I feel dumb indeed!! Now you know why

I
>had Anonymous as my name!! )
>
>Thanks a lot for info.
>>-----Original Message-----
>>Use Typeof. For Eg
>>
>>If TypeOf dateVar Is DateTime Then
>> 'Your code
>>End If
>>
>>--
>>HTH,
>>Manoj G [.NET MVP]
>>http://www15.brinkster.com/manoj4dotnet
>>
>>"Anonymous" <(E-Mail Removed)> wrote

>in message
>>news:055b01c3d4b5$5a361a10$(E-Mail Removed)...
>>> This is a pretty dumb question but I can't seem to find
>>> answer.
>>>
>>> How do you check to see if a datatype of a variable is
>>> correct? Eg in Visual Basic:
>>>
>>> Dim datevar
>>> datevar= "1a/2/2004"
>>>
>>> If IsDate(datevar) <> true then
>>> msgbox "The value in variable 'datevar' is not a

date."
>>> End if
>>>
>>> Thanks.
>>>

>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which are valid options for System.Data.DataColumn.DataType? roel.schreurs@gmail.com Microsoft ADO .NET 1 16th Jan 2007 09:20 AM
checking for a null in a bit datatype field =?Utf-8?B?Q2hyaXM=?= Microsoft C# .NET 2 30th Sep 2005 06:37 PM
Checking all contacts are valid Andrew Chalk Microsoft Outlook Contacts 0 28th Sep 2004 04:09 PM
Checking for Valid Date =?Utf-8?B?U1FMU2NvdHQ=?= Microsoft VB .NET 4 9th Sep 2004 05:49 PM
Checking for valid date Paul M. Microsoft Excel Programming 4 1st Dec 2003 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:56 AM.