vb语言 设计一个判断闰年的程序 首先在指定框中输入起止年号 然后单击判断 将闰年年号显示在列表框

vb语言 设计一个判断闰年的程序 首先在指定框中输入起止年号 然后单击判断 将闰年年号显示在列表框,第1张

  Public Function IsRunnian(ByVal n As Integer) As Boolean

        Dim res As Boolean

        res = False

        If n Mod 400 = 0 Then

            res = True

        End If

        If (n Mod 100 <> 0) And (n Mod 4 = 0) Then

            res = True

        End If

        Return res

    End Function

'窗体放一个text1用于输入年份,一个Command1

Private

Sub

Command1_Click()

dim

a%

a=

val(text1text)

if

(a

Mod

4

=

0

And

a

Mod

100

<>

0)

Or

a

Mod

400

=

0

then

print

"是闰年"

else

print

"不是闰年"

end

if

End

Sub

Private Sub Command1_Click()

Dim Y As Long, S As Long, nStr As String

nStr = InputBox("请输入年份:", "输入年份", 2000)

If nStr = "" Then Exit Sub

Y = Val(nStr)

S = DateDiff("d", Y & "-2-1", Y & "-3-1") '获取二月份的天数

If S = 29 Then nStr = "闰年" Else nStr = "不闰年"

MsgBox Y & ":" & nStr, vbInformation, "闰年判断"

End Sub

function

is_yn(num)

if

num

mod

4

=

0

then

is_yn=1

else

is_yn=0

end

if

end

function

=================

只能用function,SUB是不会返回信息的

你用is_yn(2000)就可以调用上面的函数了,返回信息为1

如果是is_yn(1991)返回信息则为0

这个其实有点儿简单,这里面最主要的一个函数就是mod取余

闰年的特点就是每4年一次,可被4除尽的,则为闰年

就是“数字 mod 4 = 0”这儿的0代表没有余数

Dim f, d As Boolean

hf:

Y = InputBox("请输入一个四位数的年份:")

If IsNumeric(Y) Then

If Len(Y) = 4 Then

a = Y / 4

For i = 1 To Len(a)

s = Mid(a, i, 1)

If s = "" Then

f = True

Exit For

End If

Next i

z = Y / 100

For i = 1 To Len(z)

t = Mid(z, i, 1)

If t = "" Then

d = True

Exit For

End If

Next i

If f = True Or d = False Then

MsgBox "不是闰年"

Else

MsgBox "闰年"

End If

Else: GoTo gf

End If

Else: GoTo gf

End If

Exit Sub

gf:

MsgBox "格式不正确!请重新输入!"

GoTo hf

以上就是关于vb语言 设计一个判断闰年的程序 首先在指定框中输入起止年号 然后单击判断 将闰年年号显示在列表框全部的内容,包括:vb语言 设计一个判断闰年的程序 首先在指定框中输入起止年号 然后单击判断 将闰年年号显示在列表框、用VB编一个程序,要求输入一个年份,判断出是否为闰年、VB编程算闰年等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/9795699.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存