# Consecutive Numbers Collection

## Recommended Posts

exam:

2+4+0+1+1+9+7+9= 33 and 3+3 = 6 like it or

0+2+0+6+1+9+8+4= 30 and 3+0= 3 this code; but dont work

thank you now

```Local \$len = StringLen('02061984')
Local \$var,\$var_1=''
for \$aa= 1 to \$len
\$var = StringMid('02061984', \$aa, 1)
\$var_1=\$var_1+number(\$var)
next
local \$ee= StringLen(\$var_1)
\$aa=''
\$var__2=''
\$var_3=''
for \$aa= 1 to \$ee
\$var_3 = StringMid(\$var_1, \$ee, 1)
\$var__2=\$var__2+number(\$var_3)
next
msgbox(0,"",\$var__2); 3```

##### Share on other sites

You add number to string.

Why?

Monkey's are, like, natures humans.

##### Share on other sites

Spot the difference?

```Local \$len = StringLen('02061984')
Local \$var,\$var_1=''
for \$aa= 1 to \$len
\$var = StringMid('02061984', \$aa, 1)
\$var_1=\$var_1+number(\$var)
next

local \$ee= StringLen(\$var_1)
\$aa=''
\$var__2 = ''
\$var_3 = ''
for \$aa = 1 to \$ee
\$var_1 = String(\$var_1)
\$var_3 = StringMid(\$var_1, \$aa, 1)
\$var__2 = \$var__2 + number(\$var_3)
next
msgbox(0,"",\$var__2); 3```
Edited by czardas

##### Share on other sites

thank you czardas

this your code worked

```Local \$len = StringLen('02061984')
Local \$var,\$var_1=''
for \$aa= 1 to \$len
\$var = StringMid('02061984', \$aa, 1)
\$var_1=\$var_1+number(\$var)
next
local \$ee= StringLen(\$var_1)
\$aa=''
\$var__2 = ''
\$var_3 = ''
for \$aa = 1 to \$ee
\$var_1 = String(\$var_1)
\$var_3 = StringMid(\$var_1, \$aa, 1)
\$var__2 = \$var__2 + number(\$var_3)
next
msgbox(0,"",\$var__2); 3```

##### Share on other sites

No problem. The error was \$ee needed to be changed to \$aa.

##### Share on other sites

```local \$hh= GUICtrlRead(\$Input1)
Local \$len = StringLen(\$hh)
Local \$var,\$var_1=''
for \$aa= 1 to \$len
\$var = StringMid(\$hh, \$aa, 1)
\$var_1=\$var_1+number(\$var)
next
local \$ee= StringLen(\$var_1)
\$aa=''
\$var__2 = ''
\$var_3 = ''
for \$aa = 1 to \$aa
\$var_1 = String(\$var_1)
\$var_3 = StringMid(\$var_1, \$aa, 1)
\$var__2 = \$var__2 + number(\$var_3)
next```

thank you

##### Share on other sites

also woking if after first step string len = 3

```MsgBox(262144, '', Total('2+4+0+1+1+9+7+9'))
MsgBox(262144, '', Total('02061984'))
;
Func Total(\$tstr)
Local \$tmp1, \$tmp2 = 0
\$tstr = StringRegExpReplace(\$tstr, "[" & StringRegExpReplace(\$tstr, "[0123456789]", "") & "]", "")
If StringLen(\$tstr) <= 1 Then Return \$tstr
\$tmp1 = StringSplit(\$tstr, "", 1)
For \$idx = 1 To \$tmp1[0]
\$tmp2 += \$tmp1[\$idx]
Next
\$tstr = Total(\$tmp2)
If StringLen(\$tstr) <= 1 Then Return \$tstr
EndFunc   ;==>Total```
Edited by SandelPerieanu

##### Share on other sites

I bet there's a way to make the SRER do the addition, but I couldn't figure that out so went with an Execute() and "+" characters.

```\$str = '02061984'

While \$str > 9
\$str = Execute(StringRegExpReplace(\$str, "(d)B", "1+"))
WEnd

MsgBox(0, "", \$str)```
Edited by Spiff59

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

×

• Wiki

• Back

• Git

## Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.