Jump to content

Missing numbers when generating host names...


Go to solution Solved by ad777,

Recommended Posts

Posted

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.....

 

Posted (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 by Nine
Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

Posted

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 here
RegExp tutorial: enough to get started
PCRE 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)

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
  • Recently Browsing   0 members

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