anybody out there who can make a program that adds a user input...
for example... if the user enters 123456...
the program must add 1+2+3+4+5+6 and display its sum;
thats all... please help me on this... really need it...
tnx a lot...
anybody out there who can make a program that adds a user input...
for example... if the user enters 123456...
the program must add 1+2+3+4+5+6 and display its sum;
thats all... please help me on this... really need it...
tnx a lot...
what you need to do is first determine the length of the string.
so let's say your string name is STRING1
dim LENstring1 as integer
LENstring1 = string1.length
next, create a variable to hold your total
also create a position valirable
dim STotal as integer
dim POS as integer = 0
now, create a loop to read your string
do while LenString1 >= 0
STotal = Stotal + val(String1.substring(POS,1)
POS = POS + 1
LenString1 = LenString1 - 1
loop
Something like that should do it. It might need to be tweaked a little.
Form has 1 textbox called TextBox1 and 1 button called button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim len1 As Integer
Dim str1 As String
str1 = TextBox1.Text
len1 = str1.Length
len1 = len1 - 1 'this is because the substring starts with index 0 instead of 1
Dim totalv As Integer
Do While len1 >= 0
totalv = totalv + Val(str1.Substring(len1, 1))
len1 = len1 - 1
Loop
TextBox1.Text = totalv
End Sub
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.