Checking for Valid Datatype

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

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.
 
That's all it is? I feel dumb indeed!! Now you know why I
had Anonymous as my name!! :o)

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

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.


.
 
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!! :o)

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

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.


.
.
 
Back
Top