【问题标题】:Number Sequence Generation in VBScriptVBScript 中的数字序列生成
【发布时间】:2013-07-04 17:07:41
【问题描述】:

我希望有一个脚本来从一个 17 字符长的数字中输出大量的连续数字(一次一百万)。 (EG 12345678912345678)

我基本上希望它像这个网站 (http://sequencegenerator.com) 一样工作,但使用我的 CPU 而不是他的。当我告诉他的网站做一百万时,他的网站就被锁定了,而我倾向于一次生成数百万。

我从网上找到了这个脚本,但我不知道任何 VisualBasic,所以我不确定如何让它为我工作。

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

【问题讨论】:

    标签: vbscript numbers generator sequential


    【解决方案1】:

    Ekkehard.Horner 的脚本稍作修改。按我的意愿工作。谢谢!

    Option Explicit
    Dim sStart : sStart = "1234567891234567"
    Dim nCount : nCount = 1000000
    Dim sPfx   : sPfx   = Left(sStart, 10)
    Dim nStart : nStart = CLng(Mid(sStart, 11))
    Dim n
    For n = 1 To nCount
    
    Dim fs
    Set fs = CreateObject("Scripting.FileSystemObject")
    Dim objLog
    set objLog = Fs.OpenTextFile("Numbers.txt", 8, true, 0)
    objLog.WriteLine sPfx & nStart
    objLog.close 
    
    nStart = nStart + 1
    Next
    

    【讨论】:

      【解决方案2】:

      为避免 VBScript 的 Double/Currency 数字的可靠范围出现所有问题,请将您的起始数字(字符串)拆分为一个稳定/永不改变的前缀和一个递增的长数字尾:

      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
      

      输出:

      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
      

      【讨论】:

      • 嗯,有个好主意 xD 如何将此输出到文本文件而不是回显?
      • 做了一些细微的修改,但现在效果很好。谢谢!
      猜你喜欢
      • 2017-02-02
      • 2023-02-20
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      相关资源
      最近更新 更多