Jump to content

About Add one


Recommended Posts

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
Link to comment
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

Link to comment
Share on other sites

$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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...