Visual Basic Programming Code Examples
Visual Basic > Date Time Code Examples
Check if year is a leap-year
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Check if year is a leap-year
'make a new project
'add a form
'add a texbox and a commandbutton
'insert the code
'press F5
Option Explicit
Private sub Command1_Click()
dim strDatum as String
If Text1.Text = "" Then exit Sub
strDatum = ("29-2-" + Text1.Text)
If IsDate(strDatum) Then MsgBox Text1.Text + " is a leap-year." _
Else MsgBox Text1.Text + " isn't a leap-year."
End Sub
Private sub Form_Load()
Text1.Text = Year(Now)
End Sub
Return