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

Author Topic: What's wrong?  (Read 3755 times)

0 Members and 1 Guest are viewing this topic.

yrrah

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    What's wrong?
    « on: January 08, 2012, 10:43:11 PM »
    I wrote this im not sure whats wrong...

    Code: [Select]
    @ECHO OFF
    title Numbers
    CLS

    :START
    ECHO 1) Login
    ECHO 2) Create
    SET /P VAR1=Choice:
    IF %VAR1%==2 GOTO CREATE
    IF %VAR1%==1 GOTO LOGIN
    IF %VAR1%== GOTO PSO


    :PSO
    CLS
    ECHO Please select one.
    GOTO START

    :CREATE
    CLS
    ECHO Please Enter a Username.
    SET /P VAR2=Username:
    IF EXIST DATA\DATA\%VAR2%.txt GOTO AT
    GOTO SP

    :AT
    CLS
    ECHO Username taken.
    ECHO Please select another one.
    GOTO CREATE2

    :CREATE2
    SET /P VAR2=Username:
    IF EXIST DATA\%VAR2%.txt GOTO AT
    GOTO SP

    :LOGIN
    CLS
    SET /P VAR3=Username:
    IF EXIST DATA\DATA\%VAR3%.TXT GOTO LS
    GOTO LF

    :LS
    CLS
    ECHO Username:%VAR3%
    SET /P VAR5=Password:
    SET /P VAR6= < DATA\DATA\%VAR3%.TXT
    IF VAR5==VAR6 ECHO O
    PAUSE
    EXIT

    :SP
    cls
    ECHO Select a password
    SET /P VAR4=Password:
    ECHO %VAR4% > DATA\DATA\%VAR2%.TXT
    EXIT

    I also wrote this to run it...
    It is converted to .exe

    Code: [Select]
    Start DATA\Numbers.bat
    This is the folder structure...

    • Numbers
    •   Number.exe
    •   Data
    •     Numbers.bat
    •       Data


    SCRAP THAT
    The
    Code: [Select]
    VAR5==VAR6needed to be
    Code: [Select]
    %VAR5%==%VAR6%

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: What's wrong?
    « Reply #1 on: January 09, 2012, 12:50:19 AM »
    Welcome!
    Computer Hope is the number one location for free computer help.
    The forum will help everyone with all computer questions.

    You are asking for help with a batch file.  There are experts here to help you.

     You can make it easier by being more specific and identify just one or two problems. That way the focus can be on just the important issues.

    BTW, have you considered using VBScript  or CScript to do .your task?
    WSH - Windows Script Host

    gpl



      Apprentice
    • Thanked: 27
      Re: What's wrong?
      « Reply #2 on: January 09, 2012, 01:05:59 AM »
      Does it work BEFORE you convert it to an exe ?
      if so, then the problem is the exe conversion - I suspect that after the conversion, the bat is not running in the directory that you think it is ... try putting in the full path to the file rather than using a relative path

      Sirim



        Rookie

        Thanked: 2
        • Experience: Familiar
        • OS: Windows 7
        Re: What's wrong?
        « Reply #3 on: January 09, 2012, 05:50:13 AM »
        Two other thing. In the below, there would be an error if the user just hit enter.

        Code: [Select]
        @ECHO OFF
        SET /P VAR1=Choice:
        IF %VAR1%==2 GOTO CREATE
        IF %VAR1%==1 GOTO LOGIN
        IF %VAR1%== GOTO PSO

        should be

        Code: [Select]
        @ECHO OFF
        set VAR1=
        SET /P VAR1=Choice:
        IF "%VAR1%"=="2" GOTO CREATE
        IF "%VAR1%"=="1" GOTO LOGIN
        IF "%VAR1%"=="" GOTO PSO

        You also need to correct every other time you use set/p such that you clear the variable before using it (set varname=) and that you use quotes (or any other character) around the comparisons on both sides, as the variable could be empty, which would cause an error:

        Code: [Select]
        IF ==2 GOTO CREATE
        is not valid code but

        Code: [Select]
        IF ""=="2" GOTO CREATE
        is fine.


        Also the path looked at by

        Code: [Select]
        :CREATE2
        SET /P VAR2=Username:
        IF EXIST DATA\%VAR2%.txt GOTO AT
        GOTO SP

        is different to the DATA\DATA path looked at by all others.