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

Author Topic: How to make (Y/N)  (Read 4571 times)

0 Members and 1 Guest are viewing this topic.

Foamy26

  • Guest
How to make (Y/N)
« on: December 11, 2007, 07:32:50 PM »
How do you make a (Y/N) at the end of a question actually work? for example
Would you like to start the "Matrix simulator" (y/n) and Y would make it continue to whatever and n would close the box. Is there anyway to do that? oh and i run on XP SP2 :D

vibhor_agarwalin



    Adviser

    Re: How to make (Y/N)
    « Reply #1 on: December 11, 2007, 10:12:43 PM »
    Just read the answer in a variable and process it.

    To read:
    set /p variable="Would you like to start the Matrix simulator (y/n)"
    Vibhor Kumar Agarwal

    devcom



      Apprentice

      Thanked: 37
      Re: How to make (Y/N)
      « Reply #2 on: December 12, 2007, 07:13:17 AM »
      try this :
      @echo off
      echo.Would you like to start the Matrix simulator?(y/n)
      set /p variable=
      if %variable% ==y (
      goto RUN
      )
      exit
      :RUN
      echo.RUN
      pause
      Download: Choice.exe

      WillyW



        Specialist
      • Thanked: 29
      • Experience: Experienced
      • OS: Windows XP
      Re: How to make (Y/N)
      « Reply #3 on: December 12, 2007, 09:33:02 AM »
      How do you make a (Y/N) at the end of a question actually work? for example
      Would you like to start the "Matrix simulator" (y/n) and Y would make it continue to whatever and n would close the box. Is there anyway to do that? oh and i run on XP SP2 :D

      Perhaps you've seen it done in the past?   If so, and it was on an older computer,  then it was probably done with the      choice       command.

      I understand that       choice.com      in not available with a WinXP installation.
      However -  you can add it.   :)

      You can download choice here:
      http://hp.vector.co.jp/authors/VA007219/dkclonesup/choice.html

      Put it in a directory that is in your path.

      Then experiment with a batch file like this one:
      Code: [Select]
      @echo off

      choice Would you like to start the "Matrix simulator

      if errorlevel 2 goto no
      if errorlevel 1 goto yes


      :no
      rem  put commands here
      echo This is what you get when you hit N

      goto end

      :yes
      rem put commands here
      echo  This is what you get when you hit Y

      goto end



      :end





      (Note:  if you are not familiar with checking for return codes (errorlevels), do
      remember to do it in descending order.   )


      As with anything like this, you experiment at your own risk. 
      I will say that the above batch file text is cut and pasted from my computer, where I played with it and it didn't blow up anything.   :)
      It is a super simple little batch file, but it should get your going in the right direction.

      Now you've got the modern way, from previous posts, of how to do it.
      And you've got the old way.     The way your question was worded, it just seemed like you should also know where the old     [Y,N]?    came from.
      :)
      .



      WillyW



        Specialist
      • Thanked: 29
      • Experience: Experienced
      • OS: Windows XP
      Re: How to make (Y/N)
      « Reply #4 on: December 12, 2007, 09:37:42 AM »
      Forgot to say:

      To get help from the choice command, use    choice /?

      The return from that here is this:
      Code: [Select]

      D:\temp>choice /?
      Waits for the user to choose one of a set of choices.

      CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

      /C[:]choices Specifies allowable keys. Default is YN
      /N           Do not display choices and ? at end of prompt string.
      /S           Treat choice keys as case sensitive.
      /T[:]c,nn    Default choice to c after nn seconds
      text         Prompt string to display

      ERRORLEVEL is set to offset of key user presses in choices.


      Just to let you know that you can do more than just  [Y,N]?  with it.   




      .



      vibhor_agarwalin



        Adviser

        Re: How to make (Y/N)
        « Reply #5 on: December 12, 2007, 11:04:50 PM »
        Never knew choice was down loadable  8)
        Vibhor Kumar Agarwal

        WillyW



          Specialist
        • Thanked: 29
        • Experience: Experienced
        • OS: Windows XP
        Re: How to make (Y/N)
        « Reply #6 on: December 13, 2007, 10:36:53 AM »
        Never knew choice was down loadable  8)

        I too learned it right here on CH.   ;)

        .



        deathavenger13



          Greenhorn

          Re: How to make (Y/N)
          « Reply #7 on: December 14, 2007, 08:57:43 AM »
          ok, after i downloaded choice, is there a specific path i need to extract it to? if so where would that be? thx

          WillyW



            Specialist
          • Thanked: 29
          • Experience: Experienced
          • OS: Windows XP
          Re: How to make (Y/N)
          « Reply #8 on: December 14, 2007, 11:09:06 AM »
          ok, after i downloaded choice, is there a specific path i need to extract it to? if so where would that be? thx

          Assuming that you want to be able to use it from any directory, here are two ways:

          1.) Put it in a directory that is already in your path.
          More info on path here:
          http://www.computerhope.com/issues/ch000549.htm     (Are you using XP?)

          and here:
          http://www.computerhope.com/pathhlp.htm


          2.)   Create a new directory.  Use it for holding utility programs that you want to be able to use from anywhere.
          Put this new directory in your path,   so that it is in your path every time you boot.
          Copy your file into this new 'utilities' directory.

          Personally,  I prefer #2 above.     It is neater and easier to keep track of, especially as time goes by and you accumulate a few more nice utility type programs that you just can't do without.   :)         Now you have already set up a place to put them.


          .



          Natrix88

          • Guest
          Re: How to make (Y/N)
          « Reply #9 on: December 14, 2007, 11:51:35 AM »
          There is another way if you don't want to download CHOICE.  It's fairly easy once you realize what it's doing, but by the looks of it it appears complex.  Here's an example.

          echo This will install Microsoft Office 2003.  Continue?
          echo  >test.txt
          erase /p test.txt >nul
          if exist test.txt goto end
          if not exist test.txt goto MSOff2003

          Here is the example again, but I'll explain what's going on.

          echo This will install Microsoft Office 2003.  Continue (Y/N)?
          echo  >test.txt                             'creates .txt file called test.txt
          erase /p test.txt >nul         'ERASE normally prompts user "Delete <file> (Y/N)?    The /p runs the command silently, so it 
                                                      isn't visible to the user.  Therefore, the user sees "This will install Micro.....(Y/N)?" and their
                                                      answer will determine if the file is deleted or not.
          if exist test.txt goto end              'if user chose N then the file still exists
          if not exist test.txt goto MSOff2003      'if user chose Y then file was deleted

          I hope that made sense...  I know CHOICE is easier, but if you are creating a batch file to run on many different computers (like I was) then you can't go around installing CHOICE on every computer.  Anyway, have fun!

          WillyW



            Specialist
          • Thanked: 29
          • Experience: Experienced
          • OS: Windows XP
          Re: How to make (Y/N)
          « Reply #10 on: December 14, 2007, 12:02:53 PM »
          ...
          echo This will install Microsoft Office 2003.  Continue?
          echo  >test.txt
          erase /p test.txt >nul
          if exist test.txt goto end
          if not exist test.txt goto MSOff2003
          ...

          Just out of curiosity,  have you tested your above by actually running it?


          .



          Natrix88

          • Guest
          Re: How to make (Y/N)
          « Reply #11 on: December 14, 2007, 01:20:36 PM »
          ...
          echo This will install Microsoft Office 2003.  Continue?
          echo  >test.txt
          erase /p test.txt >nul
          if exist test.txt goto end
          if not exist test.txt goto MSOff2003
          ...

          Just out of curiosity,  have you tested your above by actually running it?




          I did actually....  I used it to install a whole list of programs on new and rebuilt computers in the IT department of my work.  It saved about 2.5 hours of manually installing programs.  I could edit the file to how I needed the computer configured and make it run silently, and let it run as soon as the OS was installed.  I currently have it installing 13 programs.  Still works...

          S_R_S5

          • Guest
          Re: How to make (Y/N)
          « Reply #12 on: December 16, 2007, 11:34:27 PM »
          set /p x=would you like to make chocolate? (y/n)
          if %x%==y goto :y
          if %x%==n goto :n
          :y
          echo we made chocolate.
          echo press enter to exit.
          pause >nul
          echo aww well i'll make it myself
          exit