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

Author Topic: I need help with the "IF" command  (Read 3085 times)

0 Members and 1 Guest are viewing this topic.

DarkendHeart

    Topic Starter


    Beginner

    Thanked: 1
    I need help with the "IF" command
    « on: May 14, 2008, 10:46:12 PM »
    Ok well today I tried using two variables inside the "IF" command and checking to see if one variable is larger then the other, it of course is rigged for one variable, yet I continue to have it say that the smaller numbered variable is higher and continueing as if it never did the math it just went with the "goto" code at the end of the which ever "if" statement was first.
    So here's the code if what I typed doesn't make sense.
    Code: [Select]
    @echo off
    set Test=6
    set Test2=12
    if %Test% GTR %Test2% goto :Done
    if %Test2% GTR %Test% goto :Done2
    :Done
    It failed.
    pause
    :Done2
    It worked.
    pause
    Even though its rigged for "Test2" it will still goto ":Done" instead of going to where it should go which is ":Done2".
    Any one have an idea as to why. Help is greatly appreciated.

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: I need help with the "IF" command
    « Reply #1 on: May 14, 2008, 10:58:35 PM »
    It works for me....

    I cleared it up a bit. See if it works or not.

    Code: [Select]
    @echo off
    set test1=12
    set test2=6
    if %test1% GTR %test2% goto :Done1
    if %test1% LSS %test2% goto :Done2
    :done1
    echo. GTR
    pause
    exit
    :Done2
    echo LSS
    pause
    exit

    DarkendHeart

      Topic Starter


      Beginner

      Thanked: 1
      Re: I need help with the "IF" command
      « Reply #2 on: May 14, 2008, 11:01:47 PM »
      Thanks I see where it was having problems. Never really thought to do it that way. Works like a charm now. Thanks again!

      Carbon Dudeoxide

      • Global Moderator

      • Mastermind
      • Thanked: 169
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Experience: Guru
      • OS: Mac OS
      Re: I need help with the "IF" command
      « Reply #3 on: May 14, 2008, 11:02:36 PM »
      any ideas what was wrong with yours?

      DarkendHeart

        Topic Starter


        Beginner

        Thanked: 1
        Re: I need help with the "IF" command
        « Reply #4 on: May 14, 2008, 11:26:18 PM »
        It seems it wasn't liking the...
        Code: [Select]
        if %Test% GTR %Test2% goto :Done
        if %Test2% GTR %Test% goto :Done2
        For what ever reason it wasn't liking the two "IF" commands that where both seeing if one was greater then the other. So I'm guessing that was the problem.

        Carbon Dudeoxide

        • Global Moderator

        • Mastermind
        • Thanked: 169
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Experience: Guru
        • OS: Mac OS
        Re: I need help with the "IF" command
        « Reply #5 on: May 15, 2008, 02:40:30 AM »
        I would think for that you would need:
        Code: [Select]
        if %test% GTR %test2% (
           goto :Done
        ) else (
           goto :Done2
        )


        wait maybe not  :P

        DarkendHeart

          Topic Starter


          Beginner

          Thanked: 1
          Re: I need help with the "IF" command
          « Reply #6 on: May 15, 2008, 03:50:57 AM »
          Hmm, maybe I'm not 100% sure if that was the cause. Also I don't ever use the "else" statement. It never likes me enough to work right  :'(, so I just work around it. Any way thanks for all the help! Have a good day/evening/night/morning(Depending on your time zone).

          Carbon Dudeoxide

          • Global Moderator

          • Mastermind
          • Thanked: 169
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Experience: Guru
          • OS: Mac OS
          Re: I need help with the "IF" command
          « Reply #7 on: May 15, 2008, 04:08:27 AM »
          Anytime. Have a good day/evening/night/morning too.  :P

          Dias de verano

          • Guest
          Re: I need help with the "IF" command
          « Reply #8 on: May 15, 2008, 03:27:54 PM »
          Darkenedheart, your first code worked fine on my system. I think when you ran it you must have typed something different from what you posted.