mesale0077 Posted July 19, 2012 Share Posted July 19, 2012 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 Link to comment Share on other sites More sharing options...
JohnOne Posted July 19, 2012 Share Posted July 19, 2012 You add number to string. Why? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted July 19, 2012 Share Posted July 19, 2012 (edited) 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 July 19, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mesale0077 Posted July 19, 2012 Author Share Posted July 19, 2012 thank you czardasthis your code workedLocal $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 Link to comment Share on other sites More sharing options...
czardas Posted July 19, 2012 Share Posted July 19, 2012 No problem. The error was $ee needed to be changed to $aa. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
mesale0077 Posted July 19, 2012 Author Share Posted July 19, 2012 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 Link to comment Share on other sites More sharing options...
SandelPerieanu Posted July 19, 2012 Share Posted July 19, 2012 (edited) 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 July 19, 2012 by SandelPerieanu Link to comment Share on other sites More sharing options...
Spiff59 Posted July 19, 2012 Share Posted July 19, 2012 (edited) 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 July 19, 2012 by Spiff59 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now