-
Jan 30th, 2010, 08:52 AM
#1
Thread Starter
Addicted Member
[RESOLVED] IsDate always returns false
Hi guys. Was wondering why the IsDate function always returns false.
Code:
dim myYear as string
myYear = trim(txtYear.text)
If isYear(myYear) = false then
msgbox("Not a year")
End if
Do I have to define the myYear variable of the date data type? Or is there some other problem?
====================
ほんとにどもありがとう!
Rie Ishida
-
Jan 30th, 2010, 09:00 AM
#2
Re: IsDate always returns false
If you want to determine whether the contents of a string is a valid date use Date.TryParse, ie
Code:
Dim x As String = "12/02/2010"
Dim dateresult As Date
If Date.TryParse(x, dateresult) Then
MessageBox.Show("Yes its a date")
Else
MessageBox.Show("No its not a date")
End If
-
Jan 30th, 2010, 09:04 AM
#3
Thread Starter
Addicted Member
Re: IsDate always returns false
It doesn't seem to work for values that contain only a year.
Last edited by riechan; Jan 30th, 2010 at 09:07 AM.
====================
ほんとにどもありがとう!
Rie Ishida
-
Jan 30th, 2010, 09:10 AM
#4
Re: IsDate always returns false
Well a year isn't actually a date is it? Its just an integer.
What form of validation are you looking to do? Would you consider 35012 to be a year?
-
Jan 30th, 2010, 09:13 AM
#5
Thread Starter
Addicted Member
Re: IsDate always returns false
I wanted to make sure that the user inputs a valid date value, which I can also use to determine if the book is already outdated (eg: to check if the book was published 10 years or earlier from now). It's okay if I use an integer for it, but when I try to make a report using CR, it shows the Year Published value with a comma (eg: 2,010).
====================
ほんとにどもありがとう!
Rie Ishida
-
Jan 30th, 2010, 09:18 AM
#6
Re: IsDate always returns false
It's okay if I use an integer for it, but when I try to make a report using CR, it shows the Year Published value with a comma (eg: 2,010).
In that case you need to change the formatting within CR. Unfortunately I can't really help you with that but it can't be that hard.
-
Jan 30th, 2010, 10:36 AM
#7
Re: IsDate always returns false
There is a control that might help. It is DateTimePicker.
Code:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DateTimePicker1.ValueChanged
'check selected date against past date
If DateTime.Now.Date.AddYears(-10) > DateTimePicker1.Value.Date Then
Stop
End If
End Sub
-
Jan 30th, 2010, 01:03 PM
#8
Re: IsDate always returns false
Originally Posted by dbasnett
There is a control that might help. It is DateTimePicker.
Code:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DateTimePicker1.ValueChanged
'check selected date against past date
If DateTime.Now.Date.AddYears(-10) > DateTimePicker1.Value.Date Then
Stop
End If
End Sub
Yeah but the OP doesn't want a date as such - just a year. the DTP picks an actual date.
-
Jan 30th, 2010, 02:41 PM
#9
Re: IsDate always returns false
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DateTimePicker1.CustomFormat = "yyyy"
DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.ShowUpDown = True
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DateTimePicker1.ValueChanged
'check selected date against past date
If DateTime.Now.Date.AddYears(-10) > DateTimePicker1.Value.Date Then
Stop
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|