Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how to trap an error ?

T. RoehlT. Roehl Posts: 10Member
I am using Qbasic to setup & install a DOS program. One of the items is an 'Input' for a Drive letter. In testing, if an invalid drive is input, a screen return of 'Invalid drive specified' shows on the screen , but the program does not stop with an error. How can I trap or test the output ?
Code::
INPUT " Drive letter for installation " ; dr$
SHELL "" + dr$ + ":" .. (change to drive selected )
Need code to test for 'Invalide drive specified'
This does not react to ' ON ERROR GOTO '
It is like a soft error, and the program continues to run.

Thanks, T. Roehl MPLS. MN

Comments

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : I am using Qbasic to setup & install a DOS program. One of the items is an 'Input' for a Drive letter. In testing, if an invalid drive is input, a screen return of 'Invalid drive specified' shows on the screen , but the program does not stop with an error. How can I trap or test the output ?
    : Code::
    : INPUT " Drive letter for installation " ; dr$
    : SHELL "" + dr$ + ":" .. (change to drive selected )
    : Need code to test for 'Invalide drive specified'
    : This does not react to ' ON ERROR GOTO '
    : It is like a soft error, and the program continues to run.
    :
    : Thanks, T. Roehl MPLS. MN
    :

    Try this:

    SHELL "" + dr$ + ": [blue]> filename.txt[/blue]"

    On the next line, open and read that file. The results of the last command will be in there. Possibly zero-length if no error.

    The reason On Error doesn't react is because the Shell command causes DOS to do the work. QB successfully executes the shell command so no error is encountered. DOS unsuccessfully executes the change drive command, but QB doesn't know that...
  • melissa_may1melissa_may1 Posts: 937Member
    : : I am using Qbasic to setup & install a DOS program. One of the items is an 'Input' for a Drive letter. In testing, if an invalid drive is input, a screen return of 'Invalid drive specified' shows on the screen , but the program does not stop with an error. How can I trap or test the output ?
    : : Code::
    : : INPUT " Drive letter for installation " ; dr$
    : : SHELL "" + dr$ + ":" .. (change to drive selected )
    : : Need code to test for 'Invalide drive specified'
    : : This does not react to ' ON ERROR GOTO '
    : : It is like a soft error, and the program continues to run.
    : :
    : : Thanks, T. Roehl MPLS. MN
    : :
    :
    : Try this:
    :
    : SHELL "" + dr$ + ": [blue]> filename.txt[/blue]"
    :
    : On the next line, open and read that file. The results of the last command will be in there. Possibly zero-length if no error.
    :
    : The reason On Error doesn't react is because the Shell command causes DOS to do the work. QB successfully executes the shell command so no error is encountered. DOS unsuccessfully executes the change drive command, but QB doesn't know that...
    :
    Instead of KDL's way, you could just try to create a file on the drive with QB. That way, if the drive does not exist, you can yrap the error. Just delete the file if there is no error!




    [purple]Melissa[/purple]

  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Instead of KDL's way, you could just try to create a file on the drive with QB. That way, if the drive does not exist, you can yrap the error. Just delete the file if there is no error!
    :
    :
    :
    :
    : [purple]Melissa[/purple]
    :

    I thought of that, but for one problem. What if the file previously exists? Open it. No error, so delete it?? I did think of a fix for that problem. Open for Input and check the error. I think you should get a path/file access error if the drive doesn't exist...
  • melissa_may1melissa_may1 Posts: 937Member
    : : Instead of KDL's way, you could just try to create a file on the drive with QB. That way, if the drive does not exist, you can yrap the error. Just delete the file if there is no error!
    : :
    : :
    : :
    : :
    : : [purple]Melissa[/purple]
    : :
    :
    : I thought of that, but for one problem. What if the file previously exists? Open it. No error, so delete it?? I did think of a fix for that problem. Open for Input and check the error. I think you should get a path/file access error if the drive doesn't exist...
    :
    Oh, right. Well, if you're going to open for input and trap the error, then I guess you may as well trap the "invalid path" error instead. Why complicate it.

    OK, so once again...you're right oh master of the language and logic that underlies it!




    [purple]Melissa[/purple]

  • Pappy1942Pappy1942 Posts: 46Member
    Hi,
    Try this bit of code.


    ON ERROR GOTO errh
    CLS
    INPUT "drive ", d$
    dr$ = d$ + ":"
    10 CHDIR dr$
    END

    errh:
    PRINT "disk error", ERL
    RESUME NEXT 'Just goes to END


    If the drive doesn't exist or is not ready you will go to the error handling routine. What happens then is
    up to you. Once you don't have an error then use DOS to change the drive.

    Hope this helps.

    Pappy
    You learn something everyday.

  • T. RoehlT. Roehl Posts: 10Member
    : I am using Qbasic to setup & install a DOS program. One of the items is an 'Input' for a Drive letter. In testing, if an invalid drive is input, a screen return of 'Invalid drive specified' shows on the screen , but the program does not stop with an error. How can I trap or test the output ?
    : Code::
    : INPUT " Drive letter for installation " ; dr$
    : SHELL "" + dr$ + ":" .. (change to drive selected )
    : Need code to test for 'Invalide drive specified'
    : This does not react to ' ON ERROR GOTO '
    : It is like a soft error, and the program continues to run.
    :
    : Thanks, T. Roehl MPLS. MN
    :



  • T. RoehlT. Roehl Posts: 10Member
    Thanks everyone for your responces, I changed my code to use
    the Qbasic ' Open ' and then the drive letter and a temporary file. I was able to trap the error if the drive was not mapped on the network. ( Have a Great new Year )


Sign In or Register to comment.