Just beginning with batch programming
Results 1 to 8 of 8

Thread: Just beginning with batch programming

  1. #1
    Registered User Quiet Thunder's Avatar
    Join Date
    May 2001
    Posts
    1,050

    Post Just beginning with batch programming

    Hey, I just began learning batch programming, and I was woundering if anyone could help me. I'm attempting to have a small options menu, with three options, yes, no, and win98. But, The program seems to not want to let me input the yes, no, or win98. It seems to just skip over it. I know it sounds dumb, but I'm not really into programming. I'm also having problems whith the formatting, when it comes time to enter a label, the keyboard won't accecpt anytype of input. Thanks in advance.


    ECHO This program will format your c: drive and install Win 98.
    ECHO Press Y to continue or N to quit. Type MS to skip formatting and install Win 98

    IF %1. == . GOTO MENU
    IF %1 == Y GOTO CONTINUE
    IF %1 == y GOTO CONTINUE
    IF %1 == N GOTO EXIT
    IF %1 == n GOTO EXIT
    IF %1 == MS GOTO WIN98
    IF %1 == Ms GOTO WIN98
    IF %1 == ms GOTO WIN98
    IF %1 == mS GOTO WIN98

  2. #2
    Registered User
    Join Date
    Sep 2000
    Posts
    1,965

    Post

    Your batch file looks like one designed for a paramater at the command line.

    if you type batch y, then it will execute using the condition for Y.

    it you type batch n, then it will execute using the condition for N.

    if you type batch ms, then it will execution using the condition for MS.

    batch=your batch file name

    Below is an example of how it would work using paramaters
    Code:
      @ECHO OFF
    
    IF %1. == . GOTO MENU
    IF %1 == Y GOTO CONTINUE
    IF %1 == y GOTO CONTINUE
    IF %1 == N GOTO EXIT
    IF %1 == n GOTO EXIT
    IF %1 == MS GOTO WIN98
    IF %1 == Ms GOTO WIN98
    IF %1 == ms GOTO WIN98
    IF %1 == mS GOTO WIN98
    GOTO MENU
    
    :CONTINUE
    ***ROUTINE FOR FORMAT***
    
    :WIN98
    ***ROUTINE FOR WIN98 INSTALL***
    GOTO EXIT
    
    :MENU
    ECHO This program will format your c: drive and install Win 98.
    ECHO Press Y to continue or N to quit. Type MS to skip formatting and install Win 98
    
    :EXIT

  3. #3
    Registered User
    Join Date
    Jan 1999
    Location
    London, Great Britain
    Posts
    300

    Post

    You could always use the CHOICE program which allows you to wait for input from the keyboard.

    Use the DOS Help command or have a look here for more info.

    An example would be:

    Code:
    ECHO This program will format your c: drive and install Win 98.
    ECHO Press Y to continue or N to quit.
    ECHO Type W to skip formatting and install Win 98
    CHOICE /C:YNW /T:Y,5 "Your Choice:"
    The above will print the text, then wait for either Y,N or W. You can make it case sensitive with the /S switch. It will also default to the Y option in 5 seconds.

    You then check the returned value in ERRORLEVEL where 1 is the first key, 2 is the second, etc, so in our example, Y=1, N=2, W=3:

    Code:
    IF ERRORLEVEL 1 FORMAT
    IF ERRORLEVEL 2 QUIT
    IF ERRORLEVEL 3 WINDOWS
    This should just slot straight into your code!
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>

  4. #4
    Registered User Quiet Thunder's Avatar
    Join Date
    May 2001
    Posts
    1,050

    Post

    Thanks antonye, that was exactly what I wanted. Now all I gotta do if figure out why I'm getting a bad command or filename when I inserted the lines, and skip ahead to the formatting. It seems to be giving a errorlevel of 0 for somereason.

    Ok, head bleeding out of ears now.... :-) Thanks guys, you've helped a lot!!

  5. #5
    Registered User Quiet Thunder's Avatar
    Join Date
    May 2001
    Posts
    1,050

    Post

    echo off
    cls
    ECHO This program will format your c: drive and install Win 98.
    ECHO Y to Continue
    ECHO W to Skip Format and install Windows 98Se
    ECHO N to Quit Program

    CHOICE /C:YWN /T:Y,25
    IF ERRORLEVEL 3 GOTO EXIT
    IF ERRORLEVEL 2 GOTO WIN
    IF ERRORLEVEL 1 GOTO CONTINUE
    :CONTINUE
    ECHO Now Formatting
    format /u c:
    choice /c:yn /t:y,25 Install Windows? (Y/N)
    IF ERRORLEVEL 2 GOTO EXIT
    IF ERRORLEVEL 1 GOTO WIN
    :WIN
    cls
    PAUSE Please make sure the Windows 98 disk is in the cd-rom drive.
    msbatch.inf
    :EXIT
    cls

  6. #6
    Registered User
    Join Date
    Jan 1999
    Location
    London, Great Britain
    Posts
    300

    Post

    Originally posted by Quiet Thunder:
    IF ERRORLEVEL 3 GOTO EXIT
    You don't need the GOTO in there.

    It should read:

    IF ERRORLEVEL 3 EXIT

    HTH,
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>

  7. #7
    Registered User Quiet Thunder's Avatar
    Join Date
    May 2001
    Posts
    1,050

    Post

    Originally posted by antonye:
    <STRONG>

    You don't need the GOTO in there.

    It should read:

    IF ERRORLEVEL 3 EXIT

    HTH,</STRONG>

    I've tried it both with goto and without goto and it dosn't make a difference. It sitll tells me "Bad connand or file name" and won't give me the chance to enter in Y, N, or W. I just put the goto in there, because it was on the website link you gave me.

  8. #8
    Registered User Quiet Thunder's Avatar
    Join Date
    May 2001
    Posts
    1,050

    Post

    Ok, I finally figured it out. I feel like an idiot now that I know what it was. After reading through the site antonye gave me, it clicked. Apparently, I had to have a copy of command.com in the folder with my batch file. (I was testing it on a cpu with a blank HD) After adding the file, it worked! Yea. Thanks for all the help Antonye, you'll be in the credits for the readme.txt

Bookmarks

Posting Permissions

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