Dim arr1() As String Dim arr2() As String Dim intY As Integer Dim intM As Integer ' Remove extraneous spaces TextBox1.Text = TextBox1.Text.Trim ' Ensure that there is a period If Not TextBox1.Text.Contains(".") Then TextBox1.Text += "." End If ' Remove extraneous spaces TextBox2.Text = TextBox2.Text.Trim ' Ensure that there is a period If Not TextBox2.Text.Contains(".") Then TextBox2.Text += "." End If ' Split into elements of an array (Index 0=Years, Index 1=Months) arr1 = TextBox1.Text.Split(CChar(".")) arr2 = TextBox2.Text.Split(CChar(".")) ' Convert to Integers and sum the values Try intY = CInt(arr1(0)) + CInt(arr2(0)) intM = CInt(arr1(1)) + CInt(arr2(1)) Catch ex As Exception ' Integer conversion failed for one of the values MessageBox.Show("One of the inputs is not a numeric", "Error", _ MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally ' If the months value is greater or equal to 12 ' Adjust the months value and the year value If intM > 11 Then intY += intM \ 12 intM -= (intM \ 12) * 12 End If ' Assign the new computed value to the TextBox TextBox3.Text = Format(intY, "###") & "." & Format(intM, "##") End Try
Value_1
Years_1
Months_1
Value_2
Years_2
Months_2
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)