Sign in to follow this  
Followers 0
markji

About Add one

10 posts in this topic

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

Share this post


Link to post
Share on other sites



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 ,

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by czardas

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Well my code breaks if the serial only contains digits. :oops:

So just make sure it starts with a letter if you use my code above! You could end up in an infinite loop.

Edit

Statements struck out, since they were found to be untrue. :bye:

Edited by czardas

Share this post


Link to post
Share on other sites

Good job!! :oops:

Thanks you very much

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by markji

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

From these function there is no limit to the serial_num length thanks guys

That'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. :oops:

Edited by czardas

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0