• DOS Batch files

    From Spectre@21:3/101 to Somebody on Saturday, December 21, 2019 21:04:00
    I have this exceedingly ugly batchfile...

    random errorlevel
    if errorlevel 1 copy \goodbye\5.ans \sbbs\txt\goodbye.ans
    if errorlevel 2 copy \goodbye\4.ans \sbbs\txt\goodbye.ans
    if errorlevel 3 copy \goodbye\3.ans \sbbs\txt\goodbye.ans
    if errorlevel 4 copy \goodbye\2.ans \sbbs\txt\goodbye.ans
    if errorlevel 5 copy \goodbye\1.ans \sbbs\txt\goodbye.ans
    if errorlevel 6 copy \goodbye\6.ans \sbbs\txt\goodbye.ans
    if errorlevel 7 copy \goodbye\7.ans \sbbs\txt\goodbye.ans
    if errorlevel 8 copy \goodbye\8.ans \sbbs\txt\goodbye.ans
    if errorlevel 9 copy \goodbye\9.ans \sbbs\txt\goodbye.ans


    It occured to me, if I could pass a parameter to a procedure I guess you'd call
    it, I could use far few lines and stop copying larger numbers of ansi files for no good reason.

    Ergo

    random errorlevel
    goto copy %errorlevel

    :copy
    copy %something.ans goodbye.ans

    Anyone got any ideas? I don't remember having to do anything like this before, and offhand can't come up with a better idea.

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: (21:3/101)
  • From Spectre@21:3/101 to maskreet on Sunday, December 22, 2019 08:59:00
    SET /a anum=(%RANDOM%*10/32768)+1 copy \goodbye\%anum%.ans \sbbs\txt\goodbye.ans

    Didn't know there was one in ANSI.SYS.. means I'll have to load it.. its not presently although it does wonders for display nothing actually needs it. I'll give it a try see how it goes.

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: (21:3/101)
  • From Spectre@21:3/101 to Digital Man on Sunday, December 22, 2019 10:42:00
    random errorlevel if errorlevel 1 copy \goodbye\5.ans

    I'm not sure if you realize it, but "if error level 1" means "if errorlevel is greater or equal to 1". I think you mean to use "if

    Thats the only way I've ever used errorlevels, basic bbs batch file work, and why the errorlevels are always listed low to high... equal would certainly cut down the work...

    I found this which looks like it should work too.. I can easily add extra levels when and if they're needed. And just bang one copy command on the end.

    IF ERRORLEVEL 1 SET ERRORLEV=1
    IF ERRORLEVEL 2 SET ERRORLEV=2
    IF ERRORLEVEL 3 SET ERRORLEV=3
    IF ERRORLEVEL 4 SET ERRORLEV=4
    *
    *
    *
    IF ERRORLEVEL 254 SET ERRORLEV=254
    IF ERRORLEVEL 255 SET ERRORLEV=255
    ECHO ERRORLEVEL = %ERRORLEV%

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: (21:3/101)
  • From Spectre@21:3/101 to maskreet on Sunday, December 22, 2019 15:24:00
    What OS are you running? If I remember right, %RANDOM% should work
    in everything from Windows 95 and up, maybe earlier.

    MS-DOS 6.22

    For the time being I've run with the set ENV=x method and just copy %ENV%.ans at the end of them... it might be setting the variable up to 8 times, but its better than copying a file 8 times. :)

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: (21:3/101)
  • From Spectre@21:3/101 to maskreet on Sunday, December 22, 2019 15:26:00
    Also, not sure what setting a random number to a variable has to do
    with ANSI.SYS. =) The example I gave just cleans up the multipart

    My bad, misinterpretation of something you covered. All I get from.... %RANDOM%
    is a variable that is literally set with %RANDOM% in it as a text string. No errors per se.

    Spec


    --- SuperBBS v1.17-3 (Eval)
    * Origin: (21:3/101)