Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: BATCH HELP  (Read 2732 times)

0 Members and 1 Guest are viewing this topic.

devcom

    Topic Starter


    Apprentice

    Thanked: 37
    BATCH HELP
    « on: January 03, 2008, 12:51:44 PM »
    here is my code:
    Code: [Select]
    @echo off
    set /p name=
    set name=%name:A=ka% & name=%name:B=tu% & name=%name:C=mi% &
    name=%name:D=te% & name=%name:E=ku% & name=%name:F=lu% &
    name=%name:G=ji% & name=%name:H=ri% & name:I=ki% & name=%name:J=zu%
    & name=%name:K=me% & name=%name:L=ta% & name=%name:M=rin% &
    name=%name:N=to% & name=%name:O=mo% & name=%name:P=no% &
    name=%name:Q=ke% & name=%name:R=shi% & name=%name:S=ari% &
    name=%name:T=chi% & name=%name:U=do% & name=%name:V=ru% &
    name=%name:W=me% & name=%name:X=na% & name=%name:Y=fu% &
    name=%name:Z=zi%
    cls
    echo %name%
    pause >nul
    exit
    but when i write a name set command only change first letter...
    where is problem?
    « Last Edit: January 12, 2008, 09:04:19 AM by devcom »
    Download: Choice.exe

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: BATCH HELP
    « Reply #1 on: January 03, 2008, 04:38:00 PM »
    The ampersand is used to construct compound commands. Nothing is implied.  Either add a set commmand before each name= OR put each set command on a separate line.. You don't get any extra credit for having the fewest number of lines in a batch file. Putting a prompt on the set /p name= statement wouldn't hurt  either.

     :-\
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    devcom

      Topic Starter


      Apprentice

      Thanked: 37
      Re: BATCH HELP
      « Reply #2 on: January 12, 2008, 08:03:13 AM »
      I dont get what you say... Can you tell me in simple way ? Its possible or not ?
      Download: Choice.exe

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      Re: BATCH HELP
      « Reply #3 on: January 12, 2008, 08:54:42 AM »
      On
      Top
      of
      that
      it
      makes
      your
      post
      impossible
      to
      read
      .............
      " Anyone who goes to a psychiatrist should have his head examined. "

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: BATCH HELP
      « Reply #4 on: January 12, 2008, 12:16:32 PM »
      The ampersand connects multiple instructions. You cannot write one set command and expect the processor to carry it across multiple ampersands.

      Write all your set lines (except the first) as one line in your editor. If the editor wraps, that's ok, just keep typing (just like you did in your original post):

      Code: [Select]
      @echo off
      set /p set name=Enter name:
      set name=%name:A=ka% & set name=%name:B=tu% & set name=%name:C=mi% &
      set name=%name:D=te% & set name=%name:E=ku% & set name=%name:F=lu% &
      set name=%name:G=ji% & set name=%name:H=ri% & set name:%name:I=ki% & set name=%name:J=zu%
      & set name=%name:K=me% & set name=%name:L=ta% & set name=%name:M=rin% &
      set name=%name:N=to% & set name=%name:O=mo% & set name=%name:P=no% &
      set name=%name:Q=ke% & set name=%name:R=shi% & set name=%name:S=ari% &
      set name=%name:T=chi% & set name=%name:U=do% & set name=%name:V=ru% &
      set name=%name:W=me% & set name=%name:X=na% & set name=%name:Y=fu% &
      set name=%name:Z=zi%
      cls
      echo %name%
      pause >nul
      exit

      An alternative (and better) way is to put each set on a separate line:

      Code: [Select]
      @echo off
      set /p set name=Enter name:
      set name=%name:A=ka% 
      set name=%name:B=tu% 
      set name=%name:C=mi% 
      set name=%name:D=te% 
      set name=%name:E=ku% 
      set name=%name:F=lu% 
      set name=%name:G=ji% 
      set name=%name:H=ri% 
      set name=%name:I=ki% 
      set name=%name:J=zu%
      set name=%name:K=me% 
      set name=%name:L=ta% 
      set name=%name:M=rin% 
      set name=%name:N=to% 
      set name=%name:O=mo% 
      set name=%name:P=no% 
      set name=%name:Q=ke% 
      set name=%name:R=shi% 
      set name=%name:S=ari% 
      set name=%name:T=chi% 
      set name=%name:U=do% 
      set name=%name:V=ru% 
      set name=%name:W=me% 
      set name=%name:X=na% 
      set name=%name:Y=fu% 
      set name=%name:Z=zi%
      cls
      echo %name%
      pause >nul
      exit

      The set statement is not case sensitive. As far as I know there is no continuation character in batch language. I recommend you use one set statement per line.

      I have no idea what you're doing but the results should be surprising ::)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      devcom

        Topic Starter


        Apprentice

        Thanked: 37
        Re: BATCH HELP
        « Reply #5 on: January 12, 2008, 12:36:52 PM »
        oh ok thx u :) it work but there is other problem if i type ex. "b" it will make b=tu and t=chi u=do so output will be "chido" not "tu"
        Download: Choice.exe

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: BATCH HELP
        « Reply #6 on: January 12, 2008, 01:12:29 PM »
        It shouldn't be so surprising. Computers are fairly very dumb and and blindly do what they are programmed to do. I suspect you wanted to do one substitution per letter and not make substitutions for the substituted letters.

        With a little imagination you may be able to do this in batch (I'd hate to see that code) but with Windows you have other scripting languages available, either already installed (VBScript and JScript) or readily available on the net for free (Python, REXX, Perl and countless others).

        Check out VBScript at the Script Center. It's surprisingly easy to learn and much more powerful than batch.

        Good luck. 8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein