Jump to the post that solved this thread.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in getting sum of numbers program
#1
Solved: 9 Years, 9 Months, 3 Weeks ago
hi all

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
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?
Reply
Jump to the post that solved this thread.


Messages In This Thread
Error in getting sum of numbers program - by QTpier - 07-10-2014, 02:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to increase numbers for value in Excel Jyobtech 2 3,375 10-26-2012, 04:56 PM
Last Post: Jyobtech
  display any 10 numbers in ascending order using arrays in vb scripting haritha 4 23,855 01-03-2012, 05:46 PM
Last Post: shivu.hanu
  "How to write Batch Script runner program" suresz449 2 3,841 12-19-2011, 05:15 PM
Last Post: Munna.Sarfraz
  "VBScript Program" suresz449 0 2,643 12-19-2011, 09:55 AM
Last Post: suresz449
  Write a program to Capture Desktop Screen shot kumarmoyilla 2 11,469 07-11-2011, 10:51 AM
Last Post: souvikghosh_diatm

Forum Jump:


Users browsing this thread: 2 Guest(s)