|
Post by piegopher on Feb 21, 2002 2:47:28 GMT
On the old board I asked about different ways of reading the keyboard (besides inkey) I got an answer but I forgot it -Could whoever answered that please repeat it? Sorry for that...
|
|
|
Post by fly@aol.com on Feb 21, 2002 6:21:56 GMT
if I understood you correctly, you wanted the input to completely halt and the program immediately to continue on the input of the tenth character. no problem. initialize a string variable and pass it to a subroutine, like this:
sub get.input (incoming$) incoming$ = "" a$="" for x=1 to 10 do a$=inkey$ loop while a$="" if asc(a$)=13 then exit for 'enter was pressed before ' string reached ten ' characters incoming$ = incoming$ + a$ next x end sub
and that's it. you can put all sorts of good stuff in the do loop, like locate 1,70:print time$ for a continuously updated clock in the upper right hand corner. you can also put locate 20,20 : print incoming$ after adding a$ to incoming$, so the user can see what he's typing in. you can make the subroutine responsive to backspace, escape, or any number of other commands or calls. experiment.
|
|
|
Post by piegopher on Feb 22, 2002 6:54:09 GMT
Thanks, I didn't know that either- But what I meant to say was different ways of reading the keyboard instead of inkey$. All I remember of the response was something like "on key" or "on something" ....thanks for the help though ^_^ i'll probably use that as well-
|
|
|
Post by fly@aol.com on Feb 22, 2002 8:59:16 GMT
look up "on key" in your qbasic help file. they'll list the whole series of commands and codes necessary to activate any key or combination of keys to activate certain features (such as ctl-a, shift-escape, etc). if you've never spent much time in the help files, it can be quite rewarding. just jump in and start looking up things at random.
besides inkey$, there's also input, as in: input "enter a number "; variable.name
there's the extreamly useful line input, as in: print "enter a sentence" line input line$ print line$
you can do the same thing reading in a line from a file: open "filename.txt" for input as #1 do until eof(1) line input #1, line$ <do stuff> loop close #1
there's also input$. look it up.
there's also the read command, as in read data. you can have anywhere in your program a list of data that your program reads from. you can even specify where it begins reading the data. for example, the code below prints the following numbers:
4 5 6 1 2 3
restore number.2 for x = 1 to 3 read value print value next x restore number.1 for x=1 to 3 read value print value next x number.1: data 1,2,3 number.2: data 4,5,6
|
|
|
Post by fly@aol.com on Feb 22, 2002 9:04:14 GMT
actually, looking over your question again, I see I misunderstood it and once again didn't answer it directly.
input, input$, and line input all accept input directly from the keyboard.
|
|