Skip to main content

Write a VB Program to find sum of digit of a given number till it reduces to single digit. Accept input through textbox and Display the output in Message Box (using function)

· One min read
Kaustubh Kulkarni
file.vb
Private Sub Command1_Click()  

ans = display()
MsgBox ("Ansis "&ans)
End Sub
Public Function display() As Integer
s = 0
n = Val(Text1.Text)
While n > 9
s = 0
While n > 0
r = n Mod 10
s = s + r
n = n 10
Wend
n = s
Wend
display = s
End Function