barnsleystudent
02-28-2005, 08:10 AM
I have bene told that the Julian date function will prevent a innvalid date from been entered, can somebody please post the procedur.
By an invalid date i mean liek 30th February
And to take into counf ot leap years
Thanks
Hugh Lerwill
02-28-2005, 09:55 AM
I have bene told that the Julian date function will prevent a innvalid date from been entered, can somebody please post the procedur.
By an invalid date i mean liek 30th February
And to take into counf ot leap years
Thanks
The code I posted in thread
http://www.xtremevbtalk.com/showthread.php?p=896783#post896783
may be of interest (hope the link works) if not please come back
regards hugh
jjStinger72
03-01-2005, 07:35 AM
im not sure what the "Julian Date Fuction" is, and have always coded my own when i needed to get that value.
...anyway, IsDate() may help you out in this situation.
my immidiate window results
?isdate("02/28/2005")
True
?isdate("02/30/2005")
False
?isdate("x")
False
barnsleystudent
03-04-2005, 02:09 PM
I want to valid a date so that an invalid date such as 30th February can not be entered, i was given thsi code about Julian date.
Private Sub Form_Load()
Dim i As Integer
' Sets the days in each month, for refrence
days(1) = 31
days(2) = 28
days(3) = 31
days(4) = 30
days(5) = 31
days(6) = 30
days(7) = 31
days(8) = 31
days(9) = 30
days(10) = 31
days(11) = 30
days(12) = 31
' Adds values to combo box
For i = 1 To 31 ' Adds days to combo box
cboDay.AddItem Str(i)
Next i
For i = 1 To 12 ' Adds months to combo box
cboMonth.AddItem Str(i)
Next i
For i = 1905 To 1990 ' Adds years to combo box
cboYear.AddItem Str(i)
Next i
End Sub
'Calculates the number of days in february
Function daysInMonth(m, y As Integer)
If m <> 2 Then ' Need to check leap year for Feb
daysInMonth = days(m)
Else
If leapYear(y) Then
daysInMonth = 29
Else
daysInMonth = 28
End If
End If
End Function
' Checks to see if year is a leap year
Function leapYear(y As Integer)
leapYear = (y Mod 4 = 0) And ((y Mod 100 <> 0) Or (y Mod 400 = 0))
End Function
Function dateName(dd, mm, yy As Integer)
Dim d, c, m, y As Integer
m = mm - 2 ' Sep = 7, Oct = 8 etc
If m < 1 Then
yy = yy Mod 100 ' get the 2 digits of year (03)
c = (yy - y) \ 100 ' get century
d = (Int(2.6 * m - 0.2) + dd + y + Int(y / 4) + Int(c \ 4) - (2 * c) + 700) Mod 7
dateName = dayname(d)
End Function
What i want to know is how do incoperate this whith an if statment when cmd_save is cliked, will it need another procedure?
OnErr0r
03-04-2005, 02:26 PM
As jjStinger72 mentioned, the IsDate function will work nicely:
If IsDate(dYourDate) Then
' Do something with the data
Else
' Prompt that the date was invalid.
End If
If you use seperate Day, Month and Year selections, you could use the DateSerial function to generate your date variable. DateSerial is also handy to get the number of days in a month, in order to populate a days dropdown list.
Function LastDateOfMonth(ByVal lMonth As Long, ByVal lYear As Long) As Long
LastDateOfMonth = Day(DateSerial(lYear, lMonth + 1, 0))
End Function
You could call that function when the Month dropdown selection is selected, in order to clear and repopulate the days.
barnsleystudent
03-04-2005, 02:33 PM
I need to do it this way to show complexcity
OnErr0r
03-04-2005, 05:20 PM
I need to do it this way to show complexcity
Interesting.. so your plan is to take something very simple and make it overly complex?
loquin
03-04-2005, 10:54 PM
Sounds like a class assignment...