1. ホーム
  2. スクリプト・コラム
  3. vbs

vbscriptを用いた36ビット自動増加数生成コード

2022-02-09 05:45:41

aspは0から9、aからzまでの16進文字列を生成します。以下の例を実行するにはIEコアブラウザが必要で、IEコア以外のブラウザはvbscriptをサポートしません。

実装コードです。

<script language="vbscript">
function getinitstring(l) 'Initialize a 0 string of the specified length
 l=l-1
 for i=0 to l
  getinitstring="0"&getinitstring
 next
end function
function getnextchar(chrcode) 'Get the next character
 if chrcode=57 then'The numbers and letters are incoherent in ascii, need special treatment
  getnextchar="a"
 else
  getnextchar=chr(chrcode+1)
 end if
end function
function getnextno(s,l) 'Get the next self-incrementing 1 string
 if trim(s)="" then'initialize the string
  getnextno=getinitstring(l):exit function
 end if
 l=len(s)-1
 dim a():redim a(l)
 for i=0 to l'split into arrays
  a(i)=mid(s,i+1,1)
 next
 carry=false'rounding flag
 for i=l to 0 step -1'traverse from the lowest bit
  chrcode=asc(a(i))
  if carry then
   if chrcode<>122 then'if not z, self-increment and exit for loop, otherwise continue to carry
    a(i)=getnextchar(chrcode):exit for'exit the loop
   elseif i=0 then
    getnextno="The maximum length has been reached, can not continue to feed, need to modify the length":exit function
   end if
  end if
  if a(i)="z" then
   carry=true:a(i)="0"
  else
   a(i)=getnextchar(chrcode):exit for'exit loop
  end if
 next
 for i=0 to l'combine return string
  getnextno=getnextno&a(i)
 next
end function
s=""
initlen=6
s=getnextno(s,initlen)
msgbox s'000000
s=getnextno(s,initlen)
msgbox s'00000001
s="aaazzz"
s=getnextno(s,initlen)
msgbox s'aab000
s="zzzzzzz"
s=getnextno(s,initlen)
msgbox s'has reached the maximum length, can not continue to feed, need to modify the length
</script>