Results 1 to 2 of 2

Thread: date(urgent)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    2

    Angry date(urgent)

    i have created a program that allow the user to key in the expired date of credit card. if the user key in the date which is outdated ,it will pop up the message .now the problem is i would like to check the month ,day and year is that valid.if i key in the month wrongly(month>12),pop up message"invalid month".if i key in day wrongly,pop up message"invalid date", if i key in year wrongly(<2002)then pop up "Your credit card is expired".if everythings is ok,then
    the user press the"summit" button,it will pop up"Thank you for purchasing our product"
    but now if i key in the month wrongly, it suppose to pop up one message "invalid month", nut it pop up together with"invalid date!"and "Thank you for purchasing our product"
    what's wrong with my code?
    here is my code:

    private sub cmd_summit_click()
    month = Val(txt_month.Text)
    day = Val(txt_day.Text)
    year = Val(txt_year.Text)

    monthvalid = checkmonth(month)
    If Not IsEmpty(monthvalid) Then
    daynum = day_of_month(monthvalid, year)
    End If

    If Not IsEmpty(daynum) Then
    dayvalid = daycheck(day, daynum)
    End If

    If Not IsEmpty(dayvalid) Then
    yearvalid = yearcheck(dayvalid, monthvalid, year)
    End If

    End Sub

    Private Function checkmonth(m As Date) As Date

    If m > 12 Then
    Call MsgBox("Invalid month!", , "The Online Shopper")
    txt_month.SetFocus
    Else
    checkmonth = m
    End If
    End Function
    Private Function day_of_month(m As Date, y As Date) As Date


    If m = 1 Or m = 3 Or m = 5 Or m = 7 Or m = 8 Or m = 10 Or m = 12 Then
    day_of_month = 31
    End If

    If m = 4 Or m = 6 Or m = 9 Or m = 11 Then
    day_of_month = 30
    End If

    If m = 2 Then
    day_of_month = 28
    End If

    End Function

    Private Function daycheck(d As Date, dn As Date) As Date
    If d > dn Then
    Call MsgBox("Invalid date!", , "The Online Shopper")
    txt_day.SetFocus
    Else
    daycheck = d
    End If
    End Function

    Private Function yearcheck(d As Date, m As Date, y As Date)
    If y <= 2002 Then
    Call MsgBox("Your credit card is expired!")
    txt_day.SetFocus
    Else
    yearcheck = y
    End If

    End Function

  2. #2
    Lively Member
    Join Date
    Apr 2002
    Posts
    89

    hmmm

    you could cut off some of that code and make it smaller.
    oh yea, you didnt make any sense

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