网站首页 > 文章中心 > 其它

vb.net年龄计算

作者:小编 更新时间:2023-08-17 13:39:45 浏览量:348人看过

如何用VB编根据输入的生日精确计算某人的年龄

datediff的用法

vb.net获取年,月,日,时,分,秒

不是 有 函数嘛?

now() 就是 吧

取得 后 再 分离出你所需的,分别赋值 就行了,当然 还是 有 函数的

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

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

vb题 输入身份证根据出生年月日计算年纪,用到两个文本框,一个输入一个输出

Public Class 主窗体

Dim 身份证号码 As String

Dim 生日年份 As String

Dim 生日月份 As String

Dim 生日日期 As String

Dim 生日 As Date

Private Sub 输出生日按钮_Click(sender As Object, e As EventArgs) Handles 输出生日按钮.Click

Try

身份证号码 = 身份证号码输入框.Text

Else

MsgBox("请输入正确的身份证号码!", MsgBoxStyle.Information, "身份证号码有误")

身份证号码输入框.SelectAll()

身份证号码输入框.Focus()

Exit Sub

End If

If IsNumeric(生日年份) And IsNumeric(生日月份) And IsNumeric(生日日期) Then

生日 = New Date(生日年份, 生日月份, 生日日期)

生日标签.Text = 生日.ToLongDateString

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

End Class

这是 .NET 的,有疑问请追问

我在用VB.net做一个计算程序,遇到一个问题.一个数15563,需要取出万位和千位(1500)

dim a as integer

万位=a\10000

千位=a\1000 mod 10

百位=a\100 mod 10

用VB.NET编的计算器程序!

Public Class SimpleCalculator

Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()

MyBase.New()

'该调用是 Windows 窗体设计器所必需的.

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

'窗体重写处置以清理组件列表.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

MyBase.Dispose(disposing)

'Windows 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程.

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Button10 As System.Windows.Forms.Button

Friend WithEvents Button11 As System.Windows.Forms.Button

System.Diagnostics.DebuggerStepThrough() Private Sub InitializeComponent()

Me.Label1 = New System.Windows.Forms.Label

Me.TextBox1 = New System.Windows.Forms.TextBox

Me.Button1 = New System.Windows.Forms.Button

Me.Button10 = New System.Windows.Forms.Button

Me.Button11 = New System.Windows.Forms.Button

Me.SuspendLayout()

'

'Label1

Me.Label1.Name = "Label1"

Me.Label1.TabIndex = 0

Me.Label1.Text = "结果:"

'TextBox1

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = ""

'Button1

Me.Button1.Name = "Button1"

Me.Button1.Text = "清空"

'Button10

Me.Button10.Name = "Button10"

Me.Button10.TabIndex = 11

'Button11

Me.Button11.Name = "Button11"

Me.Button11.Text = "0"

'SimpleCalculator

Me.Controls.Add(Me.Button11)

Me.Controls.Add(Me.Button10)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Label1)

Me.Name = "SimpleCalculator"

Me.Text = "简单计算器"

Me.ResumeLayout(False)

#End Region

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Private Sub TextBox1_TabStopChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim btn As Button '按钮类型的变量

btn = sender '把产生该事件的按钮对象赋值给btn

TextBox1.Text = TextBox1.Text + btn.Text '把该按钮的Text属性值连接到TextBox1中

Dim btn As Button

btn = sender

TextBox1.Text += btn.Text

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

'在文本框的Text属性后连接一个空格、本按钮的Text属性值和一个空格

TextBox1.Text = TextBox1.Text + " " + btn.Text + " "

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = "" '清空文本框

'发生错误转移到标号"ErrorPro"指定的行去执行错误处理程序

On Error GoTo ErrorPro

Dim r As Decimal '保存计算结果的变量

Dim t As String = TextBox1.Text '用于保存文本框中的算术表达式

Dim space As Integer = t.IndexOf(" ") '搜索空格位置,如果没有空格,返回值为0

Dim s1 As String = t.Substring(0, space) '通过取子串方法获得第一个运算数

Dim op As String = t.Substring(space + 1, 1) '通过取子串方法获得运算符

Select Case op

Case Else

MsgBox("输入的运算符有误!")

End Select

TextBox1.Text = CStr(r) '显示结果

Exit Sub '退出过程

ErrorPro: '错误处理程序块

Select Case Err.Number

MsgBox("算术运算溢出!", , "溢出提示")

TextBox1.Focus()

MsgBox("必须输入运算符和第二个运算数!", , "运算数少")

'其它情况显示错误号和错误原因

以上就是土嘎嘎小编为大家整理的vb.net年龄计算相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章