----------------------------------- djlenny_3000 Fri Oct 29, 2004 8:45 am [tutorial] error proofing ----------------------------------- for everyone who hates it when you need an integer but someone puts in a string here is a way to stop that the key is STRINT and STRINTOK here is an example var num :int put "enter a number and i will square it" get num put num*num if someone enters "s" the program crashes so here is how you fix that % declare variables var num:int %this variable is what you ask for var input:string put "enter a number and i will square it" %the key part get input loop %this exits the loop when in the string there is a integer other forms are %strrreal intstr and realstr each converting from the first part to the %second part. if ok is on the end then it checks it first exit when strintok(input) %keep trying till they get it right put"bad input" get input end loop %now to change it from string to integer num:=strint(input) put num*num strintok checks for the integer in the string and strint converts it, if you have a question then ask. also dont forget you can use strrealok ans strreal to go from string to real and realstr or intstr to go back to string hope this helped ----------------------------------- Delos Fri Oct 29, 2004 10:42 am ----------------------------------- Hmm...ok the good parts first: This is definitely an aspect of OOT that people new to it struggle to fix. This will be a good tutorial for people who need such help. Bad parts: First off, this was supposed to error proof (trap) the input. Sadly, this has only been restricted to catching errors in terms of int-string input. Try these inputs: Ctrl + Z A string/number of more than 255 characters long Both of these crash. In other words, you're not error proofed yet. Is this problem fixable? Of course it is, find out how and update your tutorial. ----------------------------------- sw1tch Sun Jan 02, 2005 4:21 pm ----------------------------------- Hmm...ok the good parts first: This is definitely an aspect of OOT that people new to it struggle to fix. This will be a good tutorial for people who need such help. Bad parts: First off, this was supposed to error proof (trap) the input. Sadly, this has only been restricted to catching errors in terms of int-string input. Try these inputs: Ctrl + Z A string/number of more than 255 characters long Both of these crash. In other words, you're not error proofed yet. Is this problem fixable? Of course it is, find out how and update your tutorial. Why dont you tell us sir? i'd Like to know ----------------------------------- Andy Sun Jan 02, 2005 7:08 pm ----------------------------------- well to avoid the buffer overflow, simply use get input : 255 instead since then you will only be getting the first 255 characters.. but as for the ctrl+d and ctrl+c.. i have no idea how to get rid of that using ur method.. i'd just use a gui text field haha :P ----------------------------------- Tony Sun Jan 02, 2005 9:44 pm ----------------------------------- you can write your own keyboard handling methods that are based on Input.KeyDown() ----------------------------------- lasworddeladreams Wed Dec 21, 2005 8:05 pm Strintok great but not working ----------------------------------- I'm in a grade 11 compsci class and we are using Turing v6.55 which resides on a DOS disk. We've been given the same task: Make our programs crashproof. Three so far have been able to figure it out (and to think I helped them!). I've tried for hours to try to get strintok to work but alas it doesn't. I think its a great command but i cant use it. Would someone please post telling me why the command wont work? Please? :( ----------------------------------- Cervantes Wed Dec 21, 2005 8:36 pm Re: Strintok great but not working ----------------------------------- Turing v6.55 Gah?! Turing goes up to v4.1, and v4.1 is not too much more than a rumour at the moment. Would someone please post telling me why the command wont work? Please? That's a tough question, since it will work. The reason that you haven't got it to work is unknown to us, so long we can't see your code. ----------------------------------- do_pete Wed Dec 21, 2005 10:30 pm ----------------------------------- Perhaps the old DOS based Turing goes up to v.6? As for Turing 4.1 tomorow I'll post something that'll make you believe... ----------------------------------- lasworddeladreams Wed Dec 21, 2005 11:20 pm Thanks ----------------------------------- Many thanks to you Cervates and do_pete. I wasn't really expecting a reply to my post. Thanks again and as for my code here it is: var number : string var number1 : int get number : 255 loop exit when strintok(number) if number = ":" then put "This is not a number. Please try again." get number : 255 end if end loop number1 := strint(number) put number1 This is the modified version of the code our teacher gave us. Thanks again! :D ----------------------------------- McKenzie Wed Dec 21, 2005 11:20 pm ----------------------------------- Ouch... DOS version 6 ??? DOS version 8 came out about 6 years ago. I recall using 7.x about 11 years ago. Version 6 has to be at least 15 years old. ----------------------------------- McKenzie Wed Dec 21, 2005 11:25 pm ----------------------------------- As for the problem at hand, use getch, or getchar to check each character one at a time to make sure they are valid digits. Lastwords - get rid of your if in your loop "if number = ":" then" If it's a valid int the exit will kick you out of the loop. If you are still in the loop then you know it is invalid. ----------------------------------- do_pete Wed Dec 21, 2005 11:45 pm ----------------------------------- Yes you have to get rid of the if statement because it'll only ask for another number if the input is within that range. And dont bother with getch, get will work fine ----------------------------------- lasworddeladreams Thu Dec 22, 2005 7:47 am Thanks again! ----------------------------------- I'd like to thank you McKenzie and do_pete for your posts. I have since modified my program. Unfortunately, it still does not work. Turing keeps telling me that strintok has not been declared. Guess it's because we're using Turing v6.55 for MS-DOS v6.22. Anyway, following your instructions, I came up with this: var number : string var number1 : int loop get number : 255 exit when strintok(number) end loop number1 := strint(number) put number1 Thanks for all your help! :D ----------------------------------- Draymire Thu Nov 20, 2008 9:08 am RE:[tutorial] error proofing ----------------------------------- i Have found a way to crash proof a program completely from operations such as ctrl-z. use this simple yet effective program to do it var input:string(1) var output:string:="" loop getch (input) exit when input=chr(10)% a space put input .. output:=output+input exit when length(output)=255 end loop put"" put output the answer was the simple use of getch. if combined with the strintok commands you could completely idiot proof all your programs.