Search code examples
vbscriptnumbersgeneratorsequential

Number Sequence Generation in VBScript


I am looking to have a script to output a large amount of sequential numbers (One million at a time) from a number that is 17 char's long. (EG 12345678912345678)

I essentially want it to work like this site (http://sequencegenerator.com) but use MY CPU and not his. His site locks up when I tell it to do a million and I tend to generate many millions at a time.

I found this script from online, but I don't know any VisualBasic so I am unsure how to make it work for me.

Set WSHShell = Wscript.CreateObject("WScript.Shell")       
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject") 
Set EnvVar = wshShell.Environment("Process")
tBestand= EnvVar("USERPROFILE") & "\Desktop\HexNumbers.txt"
Set Bestand = fso.createtextfile(tBestand,1)
For x = 1486262272 To 1486461337
Bestand.WriteLine(hex(x))
Next
Bestand.close
WScript.quit

Solution

  • To avoid all problems with the reliable range of VBScript's Double/Currency numbers, split your start number (string) into a stable/never changing prefix and a Long number tail that gets incremented:

    Option Explicit
    
    Dim sStart : sStart = "12345678901234567"
    Dim nCount : nCount = 20
    
    Dim sPfx   : sPfx   = Left(sStart, 10)
    Dim nStart : nStart = CLng(Mid(sStart, 11))
    Dim n
    For n = 1 To nCount
        WScript.Echo sPfx, nStart, sPfx & nStart
        nStart = nStart + 1
    Next
    

    output:

    1234567890 1234567 12345678901234567
    1234567890 1234568 12345678901234568
    1234567890 1234569 12345678901234569
    1234567890 1234570 12345678901234570
    1234567890 1234571 12345678901234571
    1234567890 1234572 12345678901234572
    1234567890 1234573 12345678901234573
    1234567890 1234574 12345678901234574
    1234567890 1234575 12345678901234575
    1234567890 1234576 12345678901234576
    1234567890 1234577 12345678901234577
    1234567890 1234578 12345678901234578
    1234567890 1234579 12345678901234579
    1234567890 1234580 12345678901234580
    1234567890 1234581 12345678901234581
    1234567890 1234582 12345678901234582
    1234567890 1234583 12345678901234583
    1234567890 1234584 12345678901234584
    1234567890 1234585 12345678901234585
    1234567890 1234586 12345678901234586