Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XPp 'DOS' Variable (XPp SP1)

    Slightly off post here, but can anyone see why this simple DOS script doesn't work? It always evaluates to the variable "NO". I should stick to VBA and JS, rather than this simple DOS stuff?!

    TIA,

    Ade

    **************************
    @ECHO OFF

    SET /p userin=Are you connected to the network? Press Y for Yes, or N for No...

    IF NOT "userin"=="Y" GOTO No
    IF "userin"=="Y" GOTO Yes

    :Yes
    ECHO You answered Yes
    GOTO End

    :No
    ECHO You answered No

    :End
    Pause
    **************************

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: XPp 'DOS' Variable (XPp SP1)

    To refer to a variable, you must enclose it in % characters. "userin" is just a literal string.

    IF NOT "%userin%"=="Y" GOTO No
    IF "%userin%"=="Y" GOTO Yes

    (the last line is actually superfluous in this version, but your batch file probably contains a lot more.)

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XPp 'DOS' Variable (XPp SP1)

    Many thanks for that - knew the variable wasn't being declared properly. Like I said, I should stick to VBA and JS...!

    (and yes, there is a lot more to the script).

    Thanks again,

    Ade

  4. #4
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XPp 'DOS' Variable (XPp SP1)

    Ade,

    I just noticed one potential "gotcha", which may or may not be relevant to your usage:
    if the user types "y" then this will be interpretted as NOT "Y".
    Perhaps the following logic might be safer:

    IF "userin"=="y" GOTO Yes
    IF "userin"=="Y" GOTO Yes
    GO TO No

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Edinburgh, Midlothian, Scotland
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: XPp 'DOS' Variable (XPp SP1)

    Yep, came across that about an hour ago...many thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •