13,504,941 members
See more:
i made a text 3 text boxes and one button in that three text boxes i enter

DOB like ex:21 07 1993 format in textboxes 4,5,6 i will get out put as 2+1+0+7+1+9+9+3=34>3+4=7 in that means 7 will come as output in 7th text box. my problem if enter b'day like :1 3 1986 > 1+3+1+9+8+6=28 > 2+8=10 here "10" is displayed in 7th text box. but i want output as 1+0= 1 i.e "1" as output(in case to two digit numbers) how can i do that please tell me

i tried this
```Private Sub KryptonButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
Dim i As Integer = 0
Dim l As Integer = 0
Dim lcn As String
If TextBox4.Text = "" And TextBox5.Text = "" Then
End If
For Each digit In (TextBox4.Text + TextBox5.Text + TextBox6.Text)
i += Val(digit)
Next
lcn = i.ToString
For Each digit In lcn
l += Val(digit)
Next
TextBox7.Text = l.ToString

End Sub```

Posted 28-Dec-12 5:26am
Updated 28-Dec-12 5:32am
v4

## Solution 1

```For Each digit In (TextBox4.Text + TextBox5.Text + TextBox6.Text).ToCharArray()
i += CInt(digit)```

Convert it to a CharArray first

## Solution 2

I would create a function, that took a string as it's parameter, and returned a value that was the digits added together.
```Private Function AddDigits(s As String) As Integer
Dim result As Integer = 0
For Each c As Char In s
If [Char].IsDigit(c) Then
result += AscW(c - "0"C)
End If
Next
Return result
End Function```

I would then use a loop to call this until I had only one digit left:
```Dim str As String = "123324::34"
Dim res As Integer = 0
Do
str = res.ToString()
Loop While res >= 10
myTextBox.Text = str```

## Solution 3

Hi,

Try this:
```Private Sub KryptonButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles KryptonButton1.Click
Dim i As Integer = 0
Dim l As Integer = 0
Dim lcn As String = ""
If String.IsNullOrEmpty(textBox4.Text) AndAlso String.IsNullOrEmpty(textBox5.Text) AndAlso String.IsNullOrEmpty(textBox6.Text) Then
Return
End If
Dim dateOfBirthWithoutSpaces As String = (TextBox4.Text + TextBox5.Text + TextBox6.Text).Replace(" ", "")
For Each c As Char In dateOfBirthWithoutSpaces
i += (Convert.ToInt32(c.ToString()))
Next
lcn = i.ToString()
While lcn.Length > 1
l = 0
For Each c As Char In lcn
l += (Convert.ToInt32(c.ToString()))
Next
lcn = l.ToString()
End While
TextBox7.Text = lcn
End Sub```

Hope this helps.
v4
charuwaka 28-Dec-12 12:07pm

Dear ProgramFOX,

what i want is if i enter date like in three text boxes "01 03 1986" according you & i solution is "10" but i want 1+0= "1" i.e i want 1 as out put in case of two digit please help me ex: 23 07 1993 output is "7" this OK i want answer in case of two digit!!!!!!!
ProgramFOX 28-Dec-12 12:14pm

charuwaka 28-Dec-12 19:03pm

Thanks my Problem Solved
ProgramFOX 29-Dec-12 3:34am

You're welcome!

## Solution 4

Try creating a function that will add the values. You can change the code below to what you want.

```Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Day As String = "1"
Dim Month As String = "3"
Dim Year As String = "1986"
Dim Holder As Integer = 0

For Each num As Char In (Day + Month + Year)
Holder += Val(num)
Next

End Sub

Function AddString(number As String) As String
Dim i As Integer = 0

For Each num As Char In number
i += Val(num)
Next

If i >= 10 Then
End If

Return i.ToString()
End Function```
v2

## Solution 5

```'
' This is a Very Simple Solution applicable for any Number, It Based on Simple Maths
' It so Easy, No need to Work with Loops or Goto's
'
' Any Number (Mod) 9 = Sum Of Digits
'
' 12 Mod 9 = 3
' 21 Mod 9 = 3
' 28 Mod 9 = 1 (2+8 = 1+0 = 1)
' One Validation of Any Number / 9 = 0 then Sum of Digit is 9
' 27 Mod 9 = 0
' Hence Sum of Digit is 9
'
Function SumOfDigits(DOB As Long) As Integer
'One Line Calculation
SumOfDigits =  DOB Mod 9

'One more Validation
If SumOfDigits = 0 AND DOB <> 0 Then SumOfDigits = 9

'Return Result
Return SumOfDigits
End Function```
GeekBond 29-Dec-12 6:06am

Nice work. +5
Ashok19r91d 29-Dec-12 6:07am

Thanks...

Top Experts
Last 24hrsThis month
 Wendelius 265 OriginalGriff 218 Richard MacCutchan 50 ppolymorphe 40 Maciej Los 40
 OriginalGriff 4,181 Jochen Arndt 2,328 ppolymorphe 2,043 Wendelius 1,823 Maciej Los 1,694