Post by DARKNIGHT on Feb 5, 2024 19:01:22 GMT -5
hey Guys,
I am working on a new program,but have a problem with Error trapping.
if the line in question is in place, it traps the errors just fine,but it also wont allow the user to enter a file name to open or create one.
this program Allows a user to easily open or create a Data File.
you can Enter '?' or 'Ins' for help or instructions at the prompt near the bottom of the screen.
if the file name entered, does not already exist, the program will prompt with 'File Name; does not exist, Create it? <y/n>.
Important: to set up the program, enter the file name,"dummy" at the prompt at the bottom of screen. and select ' y' to create it.
this will create the file that lists all the saved recs
and besides the one problem, it should be good to go
just don't use any commas in your text. it causes the text to skip to next line.
the problem line resides in the [Start] Sub, and is remed out, and has an asterisk an comment to this effect.
I would like to be able to trap option Errors, but still allow a user to enter a file name to load,or create one.
I am almost done with the program, just this one problem is stopping me.
any help would be appreciated. Thanks Guys!
Here is the code:
[Start]' * Get User Command Input
locate 3,28:input"Com: > ";Fn$
cls
if Fn$="List" then [List_Recs]
if Fn$="Clr" then cls:gosub [Start]
if Fn$="?" then [HLP]
if Fn$="Ins" then [Man]
if Fn$="" then gosub [Start]
'if Fn$<>"List" or Fn$<>"Ins" or Fn$<> "Clr" then [Sys_Err]'** Problem Line
on error goto [Err]
[Open_File]' * Open Selected File Name
open Fn$ for input as #1
gosub [Read]
close #1:end
[Err]'* trap File not Found Err
if Err=53 then gosub [New]' * File Does not exist. Prompt user if they wish to Add it
end
[New]'* If file not found, ask user if they want to create it
locate 5,8:print "File named '";Fn$;"' Not found"
locate 5,9:input"Create it? <y/n>:";Yn$
if Yn$="y" then [Cr_New]
cls
gosub [Start]
[Read]' * If record found, Print contents on Scrn.
locate 7,4:print"FILE NAME: ";Fn$
locate 5,5:print"----------------------------------------------------------------------------------------------"
let a=7:let b=1
[Read_Loop]
input #1,a$(b)
locate 6,a:print a$(b)
let a=a+1
if eof(#1)=0 then [Read_Loop]
close #1
locate 5,29:Input"Press 'Enter'-> ";rt$
cls
gosub [Start]
[Cr_New]' * Allow user Add Data to the new Datafile
cls
locate 5,3:print"Enter Data for File Named ";Fn$
open Fn$ for output as #2
let a=1:let b=5
10 locate 5,b:input"";d$(a)
if d$(a)="" then gosub [Save]
let a=a+1:let b=b+1
goto 10
[Save]' * Save all lines of data entered.
for y=1 to a
print #2,d$(y)
next y
[Add]'* Add new record to File Listing
open"list_Recs" for Append as #1
print #1,Fn$;",";date$("mm/dd/yy")
close #1
print"New File Created "
Input"Press 'Enter'-> ";rt$
cls
gosub [Start]
[List_Recs]'* print list of existing Recs on Scrn.
open"list_Recs" for input as #3
let a=9
locate 6,3:print"*** FILE LISTING ***"
locate 6,4:print"--------------------"
locate 3,6:print"=============================================="
locate 3,7:print"| FILE NAME CREATION DATE |"
locate 3,8:print"=============================================="
[Loop]' * Cycle Recs in list file, print on Scrn
input #3,Fname$,CD$
locate 5,a:print Fname$
locate 35,a:print CD$
let a=a+1
if eof(#3)=0 then gosub [Loop]
close #3
'locate 3,30:print"{ Press 'Enter' to Clear Screen }"
gosub [Start]
[Sys_Err]' * User entered a non understood Command
locate 3,27:print"<<< SYNTAX ERROR >>>":playwave "Ding"
gosub [Start]
[HLP]
cls
locate 30,2:print" COMMAND LIST "
locate 30,3:print"----------------"
locate 10,5:print"COMMAND ACTION"
locate 10,6:print"==============================================================="
locate 10,8:print" List List Saved File Names"
locate 10,10:print" ? This Help File"
locate 10,12:print" Ins Instructions of Use"
locate 10,23:input"Press 'Enter' to Return to Command Prompt -> ";rt$
cls
gosub [Start]
[Man]
cls
locate 34,4:print" INSTRUCTIONS"
locate 34,5:print"--------------"
locate 6,7:print" (1) BASIC COMMANDS "
locate 6,9:print" (1.1) Entering Commands "
locate 6,10:print" -------------------------"
locate 6,11:print"when Entering a command, Be sure to Capitalize the first Letter."
locate 6,12:print"if this is Omitted, or a typo Occurs, a Syntext error will Be"
locate 6,13:print"displayed,and you will be returned to the Command prompt"
locate 6,15:print"(2) FILE CREATION AND RECALL"
locate 6,17:print" ---------------------------"
locate 6,18:Print" To create a New File, Simply Enter its Name at the Command Prompt."
locate 6,19:print" If the File does not already exist,the system will prompt:"
locate 6,20:print"'File Name' does not Exist, Create it ? <y/n>"
locate 6,22:print" Entering 'y' will prompt you to 'Enter Data' for the file."
locate 6,23:print" Press 'Enter at the end of Each line of Text,to move to the next line."
locate 6,24:print" to save your text:press 'Enter' at the next empty prompt."
locate 6,26:print" Entering 'n' clears the screen, and returns you to the command prompt"
locate 6,27:input "NEXT -> ";n$
' * Page-2
let Flag$="p2"
cls
locate 34,4:print" INSTRUCTIONS"
locate 34,5:print"--------------"
locate 6,7:print"(2) FILE CREATION AND RECALL"
locate 6,9:print" (2.2) RECALLING SAVED RECORDS "
locate 6,10:print" To Recall a saved record,Enter its name at the command Prompt,and the file will"
locate 6,11:print" be opened and appear on the screen"
locate 6,13:print" (2.3) LISTING SAVED RECORDS"
locate 6,14:print" to list records saved on the system, Enter 'Lst' at the command prompt,"
locate 6,15:print" and a roster of saved files and their creation dates,will be printed on the screen."
20 locate 6,27:print "Enter 'p' for Prevous page or 'e' to return to Command Prompt -> ";n$
locate 72,27:input"";n$
if n$="p" and Flag$="p2" then [Man]
if n$="e" then cls:gosub [Start]
goto 20