Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1675
Number of posts: 4764

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
how to trap an error ? Posted by T. Roehl on 21 Dec 2001 at 9:25 AM
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
Report
Re: how to trap an error ? Posted by KDivad Leahcim on 21 Dec 2001 at 1:07 PM
: 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$ + ": > filename.txt"

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...
Report
Re: how to trap an error ? Posted by melissa_may1 on 22 Dec 2001 at 8:29 AM
: : 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$ + ": > filename.txt"
:
: 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!




Melissa

Report
Re: how to trap an error ? Posted by KDivad Leahcim on 22 Dec 2001 at 2:09 PM
: 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!
:
:
:
:
: Melissa
:

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...
Report
Re: how to trap an error ? Posted by melissa_may1 on 22 Dec 2001 at 5:31 PM
: : 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!
: :
: :
: :
: :
: : Melissa
: :
:
: 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!




Melissa

Report
Re: how to trap an error ? Posted by Pappy1942 on 24 Dec 2001 at 10:48 AM
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.

Report
Re: how to trap an error ? Posted by T. Roehl on 31 Dec 2001 at 10:15 AM
: 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
:



Report
Re: how to trap an error ? Posted by T. Roehl on 31 Dec 2001 at 10:19 AM
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 )





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.