3. Write a VB program to find sum of digits of a given number till it reduces to single digit. Display the output using msgbox.

Dim s As Integer
Public Function display(s)
‘s = 0
n = Val(Text1.Text)
While n > 9
s = 0
While n > 0
r = n Mod 10
s = s + r
n = n \ 10
n = s
display = s
End Function

Private Sub cmdClear_Click()
Text1.Text = “”
End Sub

Private Sub CmdDisplay_Click()
sum1 = display(s)
MsgBox sum1, vbOKOnly, “Sum Of Digits”
End Sub

Private Sub Form_Activate()
End Sub


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s