hi all
I am new to scripting and i have written program which give sum of the digits in a number as follows:
I am getting Type mismatch error at
sum= sum + cInt(getdigit)
but I am not able to understand why I am getting this error because i am converting string to number.
Can somebody help me with this?
I am new to scripting and i have written program which give sum of the digits in a number as follows:
Code:
Dim num,sum,getdigit
sum=0
getdigit=""
num=Inputbox("Enter a four digit number")
If Len(num) <> 4 Then
Msgbox("Number is not four digit no")
else
For i=0 to Len(num)
getdigit=Mid(num,i+1,1)
'MsgBox(getdigit)
sum = sum+cInt(getdigit)
next
MsgBox("Sum of the digits is " & sum)
End if
sum= sum + cInt(getdigit)
but I am not able to understand why I am getting this error because i am converting string to number.
Can somebody help me with this?