• XPp ‘DOS’ Variable (XPp SP1)

    Author
    Topic
    #400426

    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
    **************************

    Viewing 3 reply threads
    Author
    Replies
    • #781123

      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.)

      • #781168

        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

      • #781169

        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

    • #781124

      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.)

    • #781251

      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

      • #781263

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

      • #781264

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

    • #781252

      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

    Viewing 3 reply threads
    Reply To: XPp ‘DOS’ Variable (XPp SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: