Cyborg5000 Posted March 30, 2022 Posted March 30, 2022 Hello i need a pointer for this piece of code. Local $sHost = "vw-aus-domdv999" ; FileRead("Test.txt") ; prefix can be anything IncrementHostName($sHost) ConsoleWrite($sHost & @CRLF) ; FileWrite("Test2.txt", $sHost) Func IncrementHostName(ByRef $sName) Local $vLast = StringRight($sName, 3) Local $vFirst = StringLeft($vLast, 1) $vLast = Number(StringRight($vLast, 2)) + 1 If $vLast > 99 Then $vLast = 1 $vFirst = Chr(Asc($vFirst) + 1) If $vFirst = ":" Then $vFirst = "a" ; change to letter If $vFirst = "{" Then $vFirst = "0" ; start all over again EndIf $sName = StringTrimRight($sName, 3) & $vFirst & StringFormat("%02i", $vLast) EndFunc ;==>IncrementHostName The host names generates just fine with the above code, however if the host name has vw-aus-domdv099, it skips -domdv100 and so on at each generation. another example is if the host name is vl-pun-domqa599 it will skip vl-pun-domqa600 and directly give vl-pun-domqa601 and so on.... i tried adding and modifiying some combinations, but nothing has changed so far.....
Solution ad777 Posted March 30, 2022 Solution Posted March 30, 2022 @Cyborg5000 the problem lies in:$vLast = 1 you have to change it to:$vLast = 0 none
Nine Posted March 30, 2022 Posted March 30, 2022 (edited) It is because you now have 3 digits at end, before you had only 2. Last must stay at 1. (not 0 as suggested). Will that be always the case (to have 3 digits) or do you need to take into account that sometimes there will be 2 and sometimes there will be 3 ? Ok, I think I understand the issue. When the 3rd char before end is numeric you want to continue with 0, but when the 3rd char is alphabetic you want to restart at 01, right ? ex : a99 will be incremented at b01 while 599 should be incremented to 600. Edited March 30, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
jchd Posted March 30, 2022 Posted March 30, 2022 Another way, works whatever number of trailing digits but doesn't expect digits in-between the leading part: Local $sHost = "vw-aus-domdv1115" IncrementHostName($sHost) ConsoleWrite($sHost & @CRLF) Func IncrementHostName(ByRef $sName) Local $aSplit = StringRegExp($sName, "^(\D+)(\d*)$", $STR_REGEXPARRAYMATCH) $sName = $aSplit[0] & StringFormat("%03i", $aSplit[1] + 1) EndFunc ;==>IncrementHostName This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jchd Posted March 30, 2022 Posted March 30, 2022 Yes but the issue with the OP's specification is that it isn't an increasing function. The successor of vw-aus-domdvz99 should be vw-aus-domdv001, making a huge step backward in the (increasing) list of already generated names. I believe this weird naming scheme has already been discussed here. 2 hours ago, Cyborg5000 said: another example is if the host name is vl-pun-domqa599 it will skip vl-pun-domqa600 and directly give vl-pun-domqa601 and so on.... Now this should give 3 digits ? Spec is inconsistant. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Nine Posted March 30, 2022 Posted March 30, 2022 @jchd See my edited post. I believe this is what OP wants... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
jchd Posted March 30, 2022 Posted March 30, 2022 Let's wait for OP decision... This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
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