Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I posted a message for help, but I didn't really get what I needed. I'm having a hard time explaining this, but thanks for the help. I need help with writing a qbasic program for a home alarm system built off of qbasic. I need to setup that when the alarm is activated the computer asks for a passcode, but it needs to be a timed response so the alarm sounds after no input, incorrect input or partially entered input is entered. I guess I just need a timed input command. Does this make anysense? can anyone help me??
Dave

Well, it's been so many years since I last programmed in QB so I can't write any code for you, but I have an idea that may prove usefull...
Since just a regular Input stops everything until a return is hit(i think) What you could do is get the system time then go into a loop. In that loop constantly check the keyboard status(using PEEK and/or POKE I think) and then just add each letter read to a string. When a backspace is read, then delete the last character added. Every time it loops check the new system time against the first time read. When the diff. is however long you want it then break from the loop and sound the alarm...
It could work, but I dont know how well. It's just a thought. If you dont know how to check the keyboard status you can find code in many QB games. Good luck, and I hope that helps some.
-Micah

I think the poster in you previous posting came pretty close. I would use also INKEY$. The problem is you would need multiple tests for the elapsed time. Also with INKEY$ you would have to test between characters input.
Are you using QBASIC under WinXP?

Thanks for the help! I think I'll be able to figure something out with this. I just wish there was something easier. I haven't used QB in years, but it's really the only thing I know how to use. I'm using my XP to program Qbasic, but the actually computer for the alarm system is just an old P1 w/98 running.
Thanks again!

===============================================================================
I wouldn't use peek/poke. Instead of the usual inkey$ routine you should use a loop that continually checks for keyed input. This loop would be the equivilent of a windows 'event' loop. As far as the timer goes, it really shouldn't need to be more complicated than reading the system time and getting the seconds and then looking for when the time has surpassed and additional specified amount of time (60 seconds for example). I don't have access to the proper information for the timer end of it but you should be able to incorporate it fairly easily. I'll try to throw some kind of an example together here to give you an idea of what I'm saying but modify it as you see fit:
10 dim k$
20 dim passwrd$, test$
21 ' here the password is hard coded but you could change this to make it more flexible
22 ' also clear test$ for posterity
30 passwrd$="password":test$=""
31 ' while loop until the two are equal
32 ' NOTE: the brackets should be less than and greater than characters
40 while test$[]passwrd$
41 ' check for a keyboard character on the fly
50 k$=inkey$
51 ' no key or extended key pressed if val(k$)=0
60 if val(k$)=0 then goto 73
61 ' if a key was entered then add it to the test
70 test$=test$+k$
71 goto 80
72 ' clear the second character in case an extended key was pressed
73 inkey$
80 wendYou don't need to test for extended key codes unless you wish to add extended keys to the test for any number of other reasons. I've bypassed all but keyboard printable characters by not doing anything if val(k$)=0. val(k$) will be equal to zero only if no key has been pressed OR an extended key has been pressed. In my example, neither is cared about so it is ignored. If you wish to use extended keys like the function keys then you will need to modify this. I hope this helps to get you started.
borelli34

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |