VB中怎样制作一个小程序。要求输入出生日期的时间,就能得到目前的年龄、出生

VB中怎样制作一个小程序。要求输入出生日期的时间,就能得到目前的年龄、出生,第1张

这个只要做一个窗体中包含三个文本框,用于输入出身的年月日,然后计算当前年龄,就要判断,如果现在的月份大约出生的月份,或现在的月份等于出生月份并且现在的日大于出生日,年龄就等于今年的年份减去出生年份,否则就等于这个值再减去一。

用VB做万年历,非常关键点就是农历写法,参考代码如下:

#Region " 返回农历 "

'返回农历

'cCalendarMaxSupportedDateTime 返回支持的最大日期,即2101-1-28

'cCalendarMinSupportedDateTime 返回支持的最小日期,即190-2-19

Private cCalendar As New SystemGlobalizationChineseLunisolarCalendar

Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String

cCalendar = New SystemGlobalizationChineseLunisolarCalendar

Dim lyear As Integer = cCalendarGetYear(sDateTime)

Dim lmonth As Integer = cCalendarGetMonth(sDateTime)

Dim lday As Integer = cCalendarGetDayOfMonth(sDateTime)

Dim lweek As Integer = cCalendarGetDayOfWeek(sDateTime)

'获取闰月, 0 则表示没有闰月

Dim leapMonth As Integer = cCalendarGetLeapMonth(lyear)

Dim isleap As Boolean = False

If (leapMonth > 0) Then

If (leapMonth = lmonth) Then

'闰月

isleap = True

lmonth = lmonth - 1

ElseIf (lmonth > leapMonth) Then

lmonth = lmonth - 1

End If

End If

Return StringConcat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))

End Function

'十天干

Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}

'十二地支

Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}

'十二生肖

Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}

'农历月

Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}

'农历日

Private days1 As String() = {"初", "十", "廿", "三"}

Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}

'返回农历年(天干 地支 生肖)

Private Function GetLunisolarYear(ByVal year As Integer) As String

GetLunisolarYear = ""

If (year > 3) Then

Dim tgIndex As Integer = (year - 4) Mod 10

Dim dzIndex As Integer = (year - 4) Mod 12

Return tiangan(tgIndex) & dizhi(dzIndex) & "[" & shengxiao(dzIndex) & "]"

End If

'无效的年份!

End Function

'返回生肖

Private Function GetShengXiao(ByVal sDateTime As Date) As String

Return shengxiao(cCalendarGetTerrestrialBranch(cCalendarGetSexagenaryYear(sDateTime)) - 1)

End Function

'返回农历月

Private Function GetLunisolarMonth(ByVal month As Integer) As String

GetLunisolarMonth = ""

If (month < 13 AndAlso month > 0) Then

Return months(month - 1)

End If

'无效的月份!

End Function

'返回农历日

Private Function GetLunisolarDay(ByVal day As Integer) As String

GetLunisolarDay = ""

If (day > 0 AndAlso day < 32) Then

If (day <> 20 AndAlso day <> 30) Then

Return StringConcat(days1((day - 1) \ 10), days((day - 1) Mod 10))

Else

Return StringConcat(days((day - 1) \ 10), days1(1))

End If

End If

'无效的日!

End Function

#End Region

VisualBasic是微软公司推出的可视化编程工具MSDN之一,是目前世界上使用最广泛的程序开发工具。

VB的语法的和QBASIB语言是基本相同的,也就是说它的语法是最容易被初学者所接受的。另外VB提供的是可视化的开发环境,我们可以象搭积木一样构建出程序的界面,而且VB提供了丰富的控件组,省去了我们自己写代码实现这些效果的麻烦,这样我们就能把更多的精力放在程序功能的实现上,所以VB学起来简单,用起来方便。

用VB写一些小程序比较有意思,想一些控件,简单的MP3等。

vb是Visual Basic的简称,是由美国微软公司于1991年开发的一种可视化的、面向对象和采用事件驱动方式的结构化高级程序设计语言,可用于开发 Windows 环境下的各类应用程序。它简单易学、效率高,且功能强大可以与 Windows 专业开发工具SDK相媲美。在Visual Basic环境下,利用事件驱动的编程机制、新颖易用的可视化设计工具,使用Windows内部的广泛应用程序接口(API)函数,动态链接库(DLL)、对象的链接与嵌入(OLE)、开放式数据连接(ODBC)等技术,可以高效、快速地开发Windows环境下功能强大、图形界面丰富的应用软件系统。

也就是说,用VB编程像画图。很有意思。

Dim n As Integer

Dim a()

Private Sub Command1_Click()

    If n = 0 Then            '第一次点击时执行

        m = Val(Text1)

        ReDim a(1 To m)

        For i = 1 To m      '生成数组a,元素为1至m这m个数

            a(i) = i

        Next

        For i = 1 To m - 1             '随机打乱数组a中元素

            r = Int(Rnd  m + 1)

            tmp = a(i)

            a(i) = a(r)

            a(r) = tmp

        Next

    End If

    n = n + 1                 '计数点击次数

    If n > Val(Text1) Then    '次数超过指定次数,抽奖结束

        MsgBox "抽奖结束!"

        Exit Sub

    End If

    Text2 = a(n)              '从数组中抽出第n个数,由于数组中是随机排列,所以相当于生成一个随机数,并且不会重复

End Sub

Private Sub Command1_Click()

Dim r As Single, y As Integer

r = 13

Do While r <= 20

r = r 101

y = y + 1

Loop

Print "我国现有人口13亿,年增长率为1%," & y & "年后增加到20亿"

End Sub

给你个计算器的代码

一个单选按钮组,里面有4个单选按钮

3个文本框

1个命令按钮

代码如下

Private Sub Command1_Click()

Dim a, b, r As Double

Dim x As Integer

a = Val(Text1Text)

b = Val(Text2Text)

r = 0

If (Option1(0)Value) Then

r = a + b

ElseIf (Option1(1)Value) Then

r = a - b

ElseIf (Option1(2)Value) Then

r = a b

ElseIf (Option1(3)Value) Then

r = a / b

End If

Text3 = r

End Sub

Private Sub Form_Load()

Option1(0)Value = True

End Sub

以上就是关于VB中怎样制作一个小程序。要求输入出生日期的时间,就能得到目前的年龄、出生全部的内容,包括:VB中怎样制作一个小程序。要求输入出生日期的时间,就能得到目前的年龄、出生、用vb编写万年历小程序、vb是什么 怎么用它来编写小程序啊、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/zz/9315285.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存