【问题标题】:what are the limits to a counter in batch批量计数器的限制是什么
【发布时间】:2022-08-18 22:06:58
【问题描述】:

我正在编写一个脚本,我正在向它添加一个计数器,但我不确定如何更好地控制它

我将此添加到我的脚本中 - 我的脚本非常大,大约 96 行,所以我试图只专注于构建计数器

Set A/ Serial=0
and then this
Set A/ serial+=1

当我运行我的 tester.txt 时,它就像上面的脚本所假设的一样

New folder 1\\tester.txt before - current script
this is the content inside my tester.txt
    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

    \"partType\": 0,
    \"partGrade\": 0,
    \"gachaConfig\": 0,
    \"amount\": 0,

我的 tester.txt 实际上将相同的代码重复 6 到 18 次

我的结果金额未正确添加

    \"partType\": 0,
    \"partGrade\": 1,
    \"gachaConfig\": 1,
    \"amount\": 1000, 

    \"partType\": 1,
    \"partGrade\": 2,
    \"gachaConfig\": 2,
    \"amount\": 5,   ---- should be 1001 also I want to increase by 500
                        or 1500 depends on the code
    \"partType\": 2,
    \"partGrade\": 3,
    \"gachaConfig\": 3,
    \"amount\": 0,  --- This 0 should not be here

    \"partType\": 3,
    \"partGrade\": 4,
    \"gachaConfig\": 4,
    \"amount\": 1,

    \"partType\": 4,
    \"partGrade\": 5,
    \"gachaConfig\": 5,
    \"amount\": 2,

    \"partType\": 5,
    \"partGrade\": 0, --- This 0 should not be here
    \"gachaConfig\": 0, --- This 0 should not be here
    \"amount\": 3,

    \"partType\": 0,
    \"partGrade\": 1,
    \"gachaConfig\": 1,
    \"amount\": 4,

    \"partType\": 1,
    \"partGrade\": 2,
    \"gachaConfig\": 2,
    \"amount\": 5,

    \"partType\": 2,
    \"partGrade\": 3,
    \"gachaConfig\": 3,
    \"amount\": 0, --- This 0 should not be here

    \"partType\": 3,
    \"partGrade\": 4,
    \"gachaConfig\": 4,
    \"amount\": 1,

    \"partType\": 4,
    \"partGrade\": 5,
    \"gachaConfig\": 5,
    \"amount\": 2,

    \"partType\": 5,
    \"partGrade\": 0, --- This 0 should not be here
    \"gachaConfig\": 0, --- This 0 should not be here
    \"amount\": 3,

    \"partType\": 0,
    \"partGrade\": 1,
    \"gachaConfig\": 1,
    \"amount\": 4,

    \"partType\": 1,
    \"partGrade\": 2,
    \"gachaConfig\": 2,
    \"amount\": 5,

    \"partType\": 2,
    \"partGrade\": 3,
    \"gachaConfig\": 3,
    \"amount\": 0, --- This 0 should not be here

    \"partType\": 3,
    \"partGrade\": 4,
    \"gachaConfig\": 4,
    \"amount\": 1,

    \"partType\": 4,
    \"partGrade\": 5,
    \"gachaConfig\": 5,
    \"amount\": 2,

    \"partType\": 5,
    \"partGrade\": 0, --- This 0 should not be here
    \"gachaConfig\": 0, --- This 0 should not be here
    \"amount\": 3,

    标签: batch-file


    【解决方案1】:

    嗯...我必须承认我对 OP 请求一无所知!但是,从问题标题和“我试图只专注于建立柜台”短语,我认为问题与计数器...

    我起初尝试生成上面相同的输出(第一次 OP 指示“我的目标”),所以我写了这个批处理文件:

    @echo off
    setlocal EnableDelayedExpansion
    
    rem Count 0..5 and repeat
    set "numbers=12"
    
    set "serial=0"
    for /L %%i in (1,1,%numbers%) do (
       echo !serial!
       set /A "serial=(serial+1)%%6"
    )
    

    然后,我有了一个想法,掸掉我旧的“Merlin 256”模型水晶球(是的,值得信赖的 16 位水晶球)并问它:“OP 真正想要的是什么?”,它回答:“一个基地-6 计数器……”

    是的当然!这很有意义,所以我最后写了这个解决方案:

    @echo off
    setlocal EnableDelayedExpansion
    
    set "numbers=25"
    
    set /A "d3=d2=d1=0"
    for /L %%i in (1,1,%numbers%) do (
       echo !d3!!d2!!d1!
       set /A "next=d1+1, d1=next%%6, C=next/6,  next=d2+C, d2=next%%6, C=next/6,  next=d3+C, d3=next%%6"
    )
    

    ...这是输出:

    000
    001
    002
    003
    004
    005
    010
    011
    012
    013
    014
    015
    020
    021
    022
    023
    024
    025
    030
    031
    032
    033
    034
    035
    040
    

    好的,第二轮...

    @echo off
    setlocal EnableDelayedExpansion
    
    del RESULTS_1.txt RESULTS_2.txt 2> NUL
    
    set /A "d2=d1=0"
    
    for /F %%a in (tester.txt) do (
       echo     %%a !d1!>> RESULTS_1.txt
       echo     %%a !d2!>> RESULTS_2.txt
       set /A "next=d1+1, d1=next%%6, C=next/6,  next=d2+C, d2=next%%6"
    )
    

    这是输入文件测试仪.txt

    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    

    结果_1.txt:

    "code" 0
    "code" 1
    "code" 2
    "code" 3
    "code" 4
    "code" 5
    "code" 0
    "code" 1
    "code" 2
    "code" 3
    "code" 4
    "code" 5
    

    结果_2.txt:

    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 0
    "code" 1
    "code" 1
    "code" 1
    "code" 1
    "code" 1
    "code" 1
    

    【讨论】:

    • 是的,是的,是的,它有效,但问题你能看看我的问题并告诉我是否正确添加它似乎有效,但执行此操作的部分11111,22222,33333,44444,55555 它停在五点,那是因为C 对所以我给了第二个代码,例如D /12,所以它可以做到这一点 66666,77777,88888,这就是我要编辑的内容
    猜你喜欢
    • 2019-07-07
    • 2016-10-23
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 2015-09-05
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多