我有 2 个组合框和 2 个文本框.我的第一个组合框以这种格式包含月份,一月、二月等,另一个组合框包含从 1 到 31 的数字.我的第一个文本框是 txtyear.一旦用户向 txtyear 输入出生年份,变量 BOD 将等于此.
Dim BOD 作为字符串BOD = cbomonth.text + "-" + cboday.text + "-" + txtyear.text我最后一个文本框的目的是处理当光标在txtyear上失去焦点时将计算的用户年龄.
谁能帮忙计算年龄.
解决方案这里真的有两个问题:
我会让你按照其他人的说明使用 TryParseExtract 这绝对是正确的方法.
根据某人的出生日期确定某人的年龄时,请尝试使用此方法:
公共函数 GetCurrentAge(ByVal dob As Date) As IntegerDim 年龄为整数年龄 = Today.Year - dob.Year如果 (dob > Today.AddYears(-age)) 那么年龄 -= 1返回年龄结束函数这是 Jeff Atwood 非常受欢迎的问题 如何计算某人的年龄的顶级答案的 vb 版本
我写了一篇关于从 dob 计算年龄 也是.
I have 2 comboboxes and 2 textboxes. My first combobox contains months in this format january, february, etc, and the other combobox contains numbers from 1 to 31. My first textbox is txtyear. Once the user input birth year to txtyear a variable BOD will be equals to this.
Dim BOD as string BOD = cbomonth.text + "-" + cboday.text + "-" + txtyear.textThe purpose of my last textbox is to handle the age of the user that will be computed when the cursor lost focus on txtyear.
Can anyone help how to compute the age.
解决方案There are really two questions here:
I'll let you follow other's instructions for how use TryParseExtract which is definitely the correct way to go here.
When determining someone's age from their DOB, try using this:
Public Function GetCurrentAge(ByVal dob As Date) As Integer Dim age As Integer age = Today.Year - dob.Year If (dob > Today.AddYears(-age)) Then age -= 1 Return age End FunctionIt is the vb version of the top answers on Jeff Atwood's very popular question How do I calculate someone's age
I wrote a blogpost about calculating age from dob as well.
更多推荐
从给定的出生日期计算年龄
发布评论