Home set date with current year as public const
Reply: 2

set date with current year as public const

Mat257
1#
Mat257 Published in 2018-02-14 17:08:54Z

i wish to set a date with fixed dd and mm but but current year, for eg 01/01/2018 or 31/01/2018, 05/08/2018 (in us dd and mm are reversed) and so on. hello guys, i wish to set a date with fixed dd and mm but but current year, for eg 01/01/2018 or 31/01/2018, 05/08/2018 (in us dd and mm are reversed) and so on. i know only number and string can be set as public const;

thereby i tried so far:

Public Const gen1 As Long = CLng(#1/1/year(date)#)

but is not working any tip please? thanks

braX
2#
braX Reply to 2018-02-14 17:29:16Z

Constants cannot have variables in them, and in VBA, you cannot Dim a variable and assign it's value at the same time like you are doing (You can in VB.NET tho).

It would be written more like this:

Public gen1 As Long 
gen1 = CLng(#1/1/year(date)#)

But that's going to give you an error too...

If you are trying to assign the value of gen1 to be the current year, all you need is this:

gen1 = Year(Date)

If you want January 1 of the current year as a Date (not a Long) then you can do it like this:

Dim gen1 as Date
gen1 = CVDate("1/1/" & Year(Date))
Kostas K.
3#
Kostas K. Reply to 2018-02-14 17:16:49Z

A public property should also be just fine:

Public Property Get TheDate() As Date
    TheDate = DateSerial(Year(Date), 1, 1)
End Property

Then just call it:

Debug.Print TheDate
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.618377 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO