Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error Trapping
#1
Ok guys, last question for a while. How can you do away with the redo from start bullcrap??? Can you use more than one set error ? Like one for every input??

ex. Your inputting numbers into an integer variable and you input a letter. How can you make it so that it goes right back to the input statement??

Also why in the hell doesn't this version of basic use direct files???
Reply
#2
use INKEY$ to process all your keyboard data.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
Code:
DO
  ' get input
  ' if input doesn't match criteria GOOD = 0 else GOOD = 1
LOOP UNTIL GOOD
Reply
#4
What you could do is come up w/ur own error codes...

Code:
'This is an example

'This is a crappy error code index:
CONST no.file=1
CONST two.file = 2
CONST out.of.range=3
'ect.....

DIM SHARED ERRORCODE AS INTEGER

ON ERROR GOTO ErrCde

'Open a non-exsistant file
ERRORCODE=no.file
OPEN "nowhere.nef" for INPUT AS #1

'Open another file from same index
ERRORCODE=two.file
OPEN "anotherfile.nef" for INPUT as #1

END

ErrCde:
SELECT CASE ERRORCODE
  CASE no.file
    STOP
  CASE two.file
    STOP
END SELECT
RESUME NEXT

You can change it to work how you need it....

Any help with it? PM me

Alex~
Reply
#5
And continuing from Agamemnus' post, Use INKEY$ to get the data, while in a loop.
If the inputted data matches ASCII codes for the numbers, ie ASCII codes 48-57, ie
Code:
qbasic IF ASC(inputtedcharacter$) => 48 and ASC(inputtedcharacter$) =< 57 THEN

then you can accept that character, and add it to the string you are bulding. at the end of the input, when the user presses ENTER, just make the string into a number.
Code:
qbasic number = VAL(inputed$)
Reply
#6
You don't need to use INKEY$...just input a string.

Code:
DO
  LINE INPUT "Enter a number: ", num$
  num$ = LTRIM$(RTRIM$(UCASE$(num$)))
  IF VAL(num$) = 0 AND num$ <> "" THEN
    'check to see if num$ is a number
    'you can make this as elaborate as you want
    'here's a simple test
    FOR i = ASC("A") to ASC("Z")
      IF INSTR(num$, chr$(i)) > 0 THEN EXIT FOR
    NEXT
    IF i = ASC("Z") + 1 THEN EXIT DO
  ELSEIF num$ <> "" THEN
    EXIT DO
  END IF
LOOP

num = VAL(num$)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)