Results 1 to 9 of 9

Thread: [RESOLVED] IsDate always returns false

  1. #1

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Resolved [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

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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

  3. #3

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    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

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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?

  5. #5

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    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

  6. #6
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    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.

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: IsDate always returns false

    Quote Originally Posted by dbasnett View Post
    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.

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width