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

Author Topic: I don't know how to set the function. IF command/Batch file  (Read 4428 times)

0 Members and 1 Guest are viewing this topic.

Mazurky

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 7
    I don't know how to set the function. IF command/Batch file
    « on: September 15, 2019, 12:04:25 AM »
    Hello.I don't know how to set the IF function in this code so that when I press 4 or 9 ... (4 to infinity) it will send me to the beginning of the code.

    This is the code
    --------------------------------------------------
    set /p udefine=
    echo.
    if %udefine%==1 start www.google.com
    if %udefine%==2 start www.youtube.com
    if %udefine%==3 start www.wikipedia.com
    if %udefine%==e goto exit
    --------------------------------------------------
    I'm tried something like this but it doesn't work
    set /p udefine=
    echo.
    if %udefine%==1 start www.google.com
    if %udefine%==2 start www.youtube.com
    if %udefine%==3 start www.wikipedia.com
    if %udefine% GEQ 4 goto top
    if %udefine%==e goto exit
    --------------------------------------------------
    I attach a batch file with code.


    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: I don't know how to set the function. IF command/Batch file
    « Reply #1 on: September 15, 2019, 10:47:43 PM »
    You may need to read this:

    How to use the Windows command line (DOS)


    The above leads to another area that lists all DOS commands. The START word is not in the list.

    You may want to use something other than a batch file.
    My preference would be a  HTML page on your desktop.  :)

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: I don't know how to set the function. IF command/Batch file
    « Reply #2 on: September 15, 2019, 11:00:37 PM »
    Add a goto with no condition after all your other if commands. If you want the batch to exit after running the start command as well, you can do something like this:

    Code: [Select]
    :top
    set /p udefine=
    echo.
    if %udefine%==1 start www.google.com&exit
    if %udefine%==2 start www.youtube.com&exit
    if %udefine%==3 start www.wikipedia.com&exit
    if %udefine%==e goto exit
    echo Unrecognized Entry.
    goto top
    I was trying to dereference Null Pointers before it was cool.

    nil

    • Global Moderator


    • Intermediate
    • Thanked: 15
      • Experience: Experienced
      • OS: Linux variant
      Re: I don't know how to set the function. IF command/Batch file
      « Reply #3 on: September 16, 2019, 05:25:28 AM »
      For reference the START command is documented here

      https://www.computerhope.com/starthlp.htm

      and indexed here

      https://www.computerhope.com/msdos.htm

      cheers
      Do not communicate by sharing memory; instead, share memory by communicating.

      --Effective Go