Jump to content

Alpabetical name generatation


Go to solution Solved by Nine,

Recommended Posts

Hi,

 

I had previously posted a thread for help, for which i had a great help from the moderators, and appreciate very much for their concerns and pointers. 

However now i have another set of pointers/help to get with the same.

Now this time it isnt a number but alphabets.

My enviroment is exhausting hostnames and will further need to drill down and start with alphabets.

Basically

  1. 1st with the help of WEBDRIVER UDF iam reading a user submitted form
  2. ,2 Further with the details captured iam going to the VC, with powercli iam searching for the last host name used as per the user's Business unit's (PLPF (Productline & Productfamily)
  3. (The start of the VM's host names may start with vw-aus-domdv001 / vw-aus-domqa001 (vw-aus-domdv/qa are not static)
  4. Once i have the last hostname used, with a small code iam generating the further list of hostnames that can be used.

;--------------------------------------------------

 

The issue/challenge is, that in some VC's and BU's iam getting over with vw-aus-domdv999 and need to further use alphabets

Example: if the last hostname was used as vw-aus-domdv999 i will have to start using vw-aus-domdva01 vw-aus-domdva02 and so on....till vw-aus-domdva90 then vw-aus-domdvb01 vw-aus-domdvb02

 

Edited by Cyborg5000
Link to comment
Share on other sites

You simply need to read the last 3 chars and decide what you're going to do with it (use StringRight function).  Then out of the 3 chars, you add the last 2 chars, if it gets over 99 then add 1 to the 3rd last char, if it gets over 9 then start using characters.

Very simple to script, so try something, and get back to us with your attempt.

Link to comment
Share on other sites

In short, you propose the following sequnce: XYZ001 to XYZ999 then XYZa01 to XYZa99 then XYZb01 to XYZb99 and so on up to XYZz99. The allowable range thusly defined for sequence XYZ is 999 + 26*99 = 3573 .

You could instead decide that the numbering of the sequence XYZ could be expressed as 3 digits in base 36. Base 36 goes from 000 to 999 then 00a to 99a then 00b to 99b and so on up to 00z to zzz. This allows for zzz₍₃₆₎ = 46655₍₁₀₎ numbers (one more if you use 000) without making the suffix any longer.

Also conversion from decimal from/to base 36 is easier than with your scheme and numbering suffixes then map trivially to decimal numbers, making it obvious to find the last sequence used.

Example use:

Local $sPrefix = "vw-aus-domdv"
Local $iLastNumber = 83 ; say you already have 83 assignations

; compute the next 30 names in this sequence
For $i = 1 To 30
    ConsoleWrite($sPrefix & _NextSuffix($iLastNumber) & @LF)
Next

Func _NextSuffix(ByRef $iLastN)
    $iLastN += 1
    Return StringFormat("%03s", _UintToString($iLastNumber, 36))
EndFunc

Func _StringToUint($s, $base)
    Return DllCall("msvcrt.dll", "uint64:cdecl", "_wcstoui64", "wstr", $s, "ptr*", 0, "int", $base)[0]
EndFunc   ;==>_StringToUint

Func _UintToString($i, $base)
    Return DllCall("msvcrt.dll", "wstr:cdecl", "_ui64tow", "uint64", $i, "wstr", "", "int", $base)[0]
EndFunc   ;==>_UintToString

The function _StringToUint() does the reverse conversion: digits in base B as string to integer. It's very rare to have a current Windows system where msvcrt.dll (Microsoft Visual C run-time library) is absent.

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)

Link to comment
Share on other sites

Hello @Nine and @jchd

Very much thanks for replaying back and giving some instights...

Appreciate your help.

 

below is my code adapted and working..

 

;Copy any of these to clipboard xxx xxxx111 , xxx11 , xxxx-xxxx-1 , xx4x11
Global $sOldContents

$File = "C:\test.txt"
$Open = FileOpen($File, 0)
$Read = FileRead($Open)
ClipPut($Read)

Local $counter = 0


Local $sCbContents = ClipGet()
While $counter <= 5
    If $sOldContents <> $sCbContents And StringRegExp($sCbContents, "(.*?)(\d)$") Then

        $sCbContents = StringReplace($sCbContents, "'", "#SingleQts#")
        $sCbContents = StringReplace($sCbContents, '"', "#DbleQts#")


        $sCbContents = Execute(StringRegExpReplace($sCbContents, "(.*?)(\d+)$", '"$1" & Number("$2") +1'))

        If @error Then

            $sCbContents = StringReplace($sCbContents, "#SingleQts#", "'")

            $sCbContents = StringReplace($sCbContents, "#DbleQts#", '"')

            $sOldContents = $sCbContents
        EndIf
    EndIf

    $counter = $counter + 1
    FileWrite("C:\test2.txt", StringRegExpReplace($sCbContents, "(\+|=|!|#|\^|\{|\})", "{\1}") & @CRLF)

WEnd


FileClose($Open)

C:\test.txt file is the file into which the last hostname that was used is gathered via powercli by quering the VC.

Please note "

Local $sPrefix = "vw-aus-domdv" ; is not static....
  1. (The start of the VM's host names may start with vw-aus-domdv001 / vw-aus-domqa001 (vw-aus-domdv/qa are not static and neither their start)
  2. vw-tlv-istqa/vw-aus-istdv, vw-pun-istdv are taken/made as per users location and BU.

My main concern is to use the above code and use if for further generating the hosts with alphabets capturing only the last 3 letters/numbers, once the host name reaches till domqa999/domdv999/domsp999, istqa999, istdv999, istsp999 (istsp/domqa/domdv are not static)

Link to comment
Share on other sites

I understand the prrefix isn't static. My post was just an example of how to use a better numbering scheme, certainly not code you can directly use in your application. You have to use a little of your own brain juice.

Edited by jchd
typo

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)

Link to comment
Share on other sites

48 minutes ago, jchd said:

I understand the ^refix isn't static. My post was just an example of how to use a better numbering scheme, certainly not code you can directly use in your application. You have to use a little of your own brain juice.

:) that's what iam trying to get help about...
unsure where or how to use your code with mine as posted...

Link to comment
Share on other sites

  • Solution

I am not sure why you have a counter in there, does not seem to be necessary.  And why do you go thru ClipBoard, seems also not necessary.

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

 

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