cesarfrancisco
Active member
- Joined
- Apr 3, 2007
- Messages
- 33
- Programming Experience
- Beginner
'Calculate age based today's and the person's birthday. Birthday can be entered like (2 2 45), (1-31-1945), 2/28/45)
PrivateSub txtboxDOB_TextChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtboxDOB.TextChanged
Dim sb AsNew System.Text.StringBuilder
Dim pos AsInteger = txtboxDOB.SelectionStart
ForEach c AsCharIn txtboxDOB.Text
SelectCase c
CaseChar.Parse("/")
sb.Append(c)
CaseChar.Parse("-")
sb.Append(c)
CaseChar.Parse(" ")
sb.Append(c)
CaseElse
IfChar.IsDigit(c) Then
sb.Append(c)
EndIf
EndSelect
Next
txtboxDOB.Text = sb.ToString
txtboxDOB.SelectionStart = pos
Dim BirthDate As DateTime
If DateTime.TryParse(txtboxDOB.Text, BirthDate) Then
BirthDate = Date.Parse(txtboxDOB.Text)
EndIf
Dim age AsInteger
If ((DateTime.Now.Month + DateTime.Now.Day / 100) < (BirthDate.Month + BirthDate.Day / 100))
age = (DateTime.Now.Year - BirthDate.Year) - 1
Else
age = (DateTime.Now.Year - BirthDate.Year)
EndIf
txtboxAge.Text = age.ToString
If age = 0 Then
txtboxAge.Text = "<1"
ElseIf age < 0 Then
txtboxAge.Text = "?"
ElseIf age > 110 Then
txtboxAge.Text = "?"
EndIf
EndSub
The problem appears when the user started to type in a DOB but relents. Now the cursor is stuck. How to remedy this?
PrivateSub txtboxDOB_TextChanged(ByVal sender AsObject, ByVal e As System.EventArgs) Handles txtboxDOB.TextChanged
Dim sb AsNew System.Text.StringBuilder
Dim pos AsInteger = txtboxDOB.SelectionStart
ForEach c AsCharIn txtboxDOB.Text
SelectCase c
CaseChar.Parse("/")
sb.Append(c)
CaseChar.Parse("-")
sb.Append(c)
CaseChar.Parse(" ")
sb.Append(c)
CaseElse
IfChar.IsDigit(c) Then
sb.Append(c)
EndIf
EndSelect
Next
txtboxDOB.Text = sb.ToString
txtboxDOB.SelectionStart = pos
Dim BirthDate As DateTime
If DateTime.TryParse(txtboxDOB.Text, BirthDate) Then
BirthDate = Date.Parse(txtboxDOB.Text)
EndIf
Dim age AsInteger
If ((DateTime.Now.Month + DateTime.Now.Day / 100) < (BirthDate.Month + BirthDate.Day / 100))
age = (DateTime.Now.Year - BirthDate.Year) - 1
Else
age = (DateTime.Now.Year - BirthDate.Year)
EndIf
txtboxAge.Text = age.ToString
If age = 0 Then
txtboxAge.Text = "<1"
ElseIf age < 0 Then
txtboxAge.Text = "?"
ElseIf age > 110 Then
txtboxAge.Text = "?"
EndIf
EndSub
The problem appears when the user started to type in a DOB but relents. Now the cursor is stuck. How to remedy this?