Fortune Telling Collection - Zodiac Analysis - Write judging constellations by date of birth in EXCEL with VB language!

Write judging constellations by date of birth in EXCEL with VB language!

In fact, the simplest idea should be to remove the year information of birthdays (such as A 1) (all unified as 1900, use the function date(0, month(A 1), day(A 1)), and then divide the dates with constellations (such as Aquarius/kloc). In the past, many online sentences used this idea to look up constellations.

But this method has a hidden bug: leap year. The constellation division day of leap year will increase by 1 after March. Hidden bugs are taboo! If someone calls your function, there will always be irregular errors. Sometimes you can't find the problem because your function has this hidden bug.

In order to bypass the bug of leap year, I wrote the following function, directly imitating the process of human flesh querying the month and day.

Of course, there are also some places that can be optimized. For example, the array of months can be directly optimized because the dimensions and contents are the same; For example, the final if statement structure can be replaced by iif statement. But these are the details. In order to better reflect the programming ideas, we will not do these "clever" optimizations.

Constellation function in string form (X stands for date)

Dim XZ( 12) as a string.

Dim Yue( 12) as the length

Dim Ri( 12) As Long

XZ(0) = "Capricorn"

XZ( 1) = "Aquarius"

XZ(2) = "Pisces"

XZ(3) = "Aries"

XZ(4) = "Taurus"

XZ(5) = "Gemini"

XZ(6) = "cancer"

XZ(7) = "Leo"

XZ(8) = "Virgo"

XZ(9) = "Libra"

XZ( 10) = "Scorpio"

XZ( 1 1) = "Sagittarius"

XZ( 12) = "Capricorn"

Yue (1) = 1

Yue (2) = 2

Yue (3) = 3

Yue (4) = 4

Yue (5) = 5

Yue (6) = 6

Yue (7) = 7

Yue (8) = 8

Yue (9) = 9

Yue (10) = 10

Yue (11) =11

Yue (12) = 12

Ri( 1) = 20

Ri(2) = 19

Ri(3) = 2 1

Ri(4) = 20

Ri(5) = 2 1

Ri(6) = 22

Ri(7) = 23

Ri(8) = 23

Ri(9) = 23

Ri( 10) = 24

Ri( 1 1) = 23

Ri( 12) = 22

M = month (x)

D = days (x)

If d< day (day (meter)) and then

Horoscope = XZ (Yue (m)-1)

other

Horoscope = XZ (month (meter))

If ... it will be over.

End function