markji Posted March 26, 2012 Share Posted March 26, 2012 I have the serial_num :qws2012 and I want change the serial_num to qws2013, qsw2014.... That mean Every time Add one How can I make it work? Wait for your help Link to comment Share on other sites More sharing options...
Country73 Posted March 26, 2012 Share Posted March 26, 2012 Example: $var = 2011 Do ConsoleWrite('qsw:' & $var & @CRLF) $var += 1 Until $var = 2020 If you try to fail and succeed which have you done?AutoIt Forum Search Link to comment Share on other sites More sharing options...
markji Posted March 26, 2012 Author Share Posted March 26, 2012 Hi Country73 Thanks for your help Base on your function I can do good job ,and what I want is that when the serial_num(qws2012) is get by the somewhere and its changed each time I want get the latest serial_num and then do add one , Link to comment Share on other sites More sharing options...
czardas Posted March 26, 2012 Share Posted March 26, 2012 (edited) Here's a simple method. It can be done differently, and perhaps more neatly, but I wanted to break it down (hopefully) into an easy to understand example. $string = "abc0123" $iStrLen = StringLen($string) $iSplitPoint = $iStrLen Do $iSplitPoint -=1 Until Not StringIsDigit(StringMid($string, $iSplitPoint)) $stringL = StringLeft($string, $iSplitPoint) $stringR = StringRight($string, $iStrLen - $iSplitPoint) $stringR +=1 While StringLen($stringR) < $iStrLen - $iSplitPoint $stringR = "0" & $stringR WEnd $sNewString = $stringL & $stringR MsgBox (0, "", $sNewString) Edited March 26, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jvanegmond Posted March 26, 2012 Share Posted March 26, 2012 Here's a simple method. It can be done differently, and perhaps more neatly, but I wanted to break it down (hopefully) into an easy to understand example. Daaamn! Lol. Perhaps the OP will rather opt for something like this: $foo = "qws2012" $foo = StringLeft($foo, 3) & StringRight($foo, 4) + 1 MsgBox(0, "", $foo) github.com/jvanegmond Link to comment Share on other sites More sharing options...
czardas Posted March 26, 2012 Share Posted March 26, 2012 (edited) Well my code breaks if the serial only contains digits. So just make sure it starts with a letter if you use my code above! You could end up in an infinite loop.EditStatements struck out, since they were found to be untrue. Edited March 26, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
markji Posted March 26, 2012 Author Share Posted March 26, 2012 Good job!! Thanks you very much Link to comment Share on other sites More sharing options...
Country73 Posted March 26, 2012 Share Posted March 26, 2012 So, from Manadar's example: If you plan to add this into a script to where you need to +1 at specific points, you can simply put this function in your script $var = 'qsw:2011' ; Current Serial_Num Consolewrite("New serial_num: " & _AddOne($var) & @crlf) ; Where you need to +1, call the function Func _AddOne($foo) $foo = StringLeft($foo, 3) & StringRight($foo, 4) + 1 Return $foo EndFunc If you try to fail and succeed which have you done?AutoIt Forum Search Link to comment Share on other sites More sharing options...
markji Posted March 26, 2012 Author Share Posted March 26, 2012 (edited) $string = "abc0123" $iStrLen = StringLen($string) $iSplitPoint = $iStrLen Do $iSplitPoint -=1 Until Not StringIsDigit(StringMid($string, $iSplitPoint)) $stringL = StringLeft($string, $iSplitPoint) $stringR = StringRight($string, $iStrLen - $iSplitPoint) $stringR +=1 While StringLen($stringR) < $iStrLen - $iSplitPoint $stringR = "0" & $stringR WEnd $sNewString = $stringL & $stringR MsgBox (0, "", $sNewString)[/size][/color][/font] [font="monospace"][color="#5a5a5a"][size=3]From these function there is no limit to the serial_num length thanks guys Edited March 26, 2012 by markji Link to comment Share on other sites More sharing options...
czardas Posted March 26, 2012 Share Posted March 26, 2012 (edited) From these function there is no limit to the serial_num length thanks guysThat's correct and it also maintains leading zeros. If you know exactly the format of the serial, then simple code like Manadar posted will do the job. If you don't know the exact format then you need to parse the string to find the split point.By the way, if you post AutoIt code using the AutoIt code tags, then first add the tags to your post and then paste the code between them. Edited March 26, 2012 by czardas operator64 ArrayWorkshop 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