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

Author Topic: Bach Programming Help  (Read 2436 times)

0 Members and 1 Guest are viewing this topic.

domingos.sn

    Topic Starter


    Greenhorn

    Bach Programming Help
    « on: July 25, 2008, 06:43:33 AM »
    Hello,

    I want to use a case structure with a batch file, but I don't know how to work with variables.

    I know it should look something like this:
    Quote
    show(Press 1 if you want to do A, 2 if you want to do B)
    :label0
    get X
    if x==1 then goto label1
    if x==2 then goto label2
         else show(invalid number, try again)
                 goto label0

    :label1
    [do A]
    goto label_end
    :label2
    [do B]
    goto label_end

    :label_end


    But I can't get how I create/define/make variables and how I get the input value for that variable.

    Could someone help me, please ?

    obs:
    Using Comand Prompt from WinServ2k3

    diablo416



      Hopeful
      Re: Bach Programming Help
      « Reply #1 on: July 25, 2008, 06:48:34 AM »
      :label0
      ::use set /p to get input, example
      set /p x=Enter your Choice:
      if "%x%"=="1" Goto Label1
      if "%x%"=="2" Goto Label2
      cls & echo You have made an invalid choice & Goto label0

      :label1
      :label2

      domingos.sn

        Topic Starter


        Greenhorn

        Re: Bach Programming Help
        « Reply #2 on: July 25, 2008, 07:16:13 AM »
        Thanks!

        Lemme just ask another question:
        What is the difference between this:

        Quote
        cls & echo You have made an invalid choice & Goto label0

        ....and this:
        Quote
        cls
        echo ...
        goto label 0
        ?

        diablo416



          Hopeful
          Re: Bach Programming Help
          « Reply #3 on: July 25, 2008, 07:32:04 AM »
          there isnt one, using & is the same as starting a new line so it looks like
          cls & echo You have made an invalid choice & Goto label0 but its really

          cls
          echo you have made an invalid choice
          goto label0



          domingos.sn

            Topic Starter


            Greenhorn

            Re: Bach Programming Help
            « Reply #4 on: July 25, 2008, 07:34:59 AM »
            Ahh! I tought it was something like that =)!

            Thanks again!