I modified his original code because I needed to give the user all the questions at once, so they knew how many fields needed to have responses and what the last field was. It gave the user the chance before hitting enter on the last field to change anything. Without knowing the last question, you don't get that chance.
I also used an idea from Dutchman where he colored his input boxes. I changed that a little bit by putting all the labels and the input boxes on the screen and when you were at a question that needed an answer, the input box color changed from white to green, and when you hit enter, it changes back to white and the next field is colored.
This helps to visually see what question needs to be answered, since it is hard to see the cursor. Also, if you go back and make changes, if you have a field that is still green, you need to hit enter to commit that response. If you do not hit enter, the value typed in will not get used.
What I did not do was to make the code more tighter and efficient as in the other changes made by the Dutchman. I left it the way ricardobytes wrote it and expanded on it so it is a clear example of how to use most of the FIELD statements, a benefit for everyone, including beginners just learning Smart Basic. I will in the next version make the coding "more efficient" as in the Dutchman's example.
I will also add in the next release a series of buttons, so when you hit enter in the last field, it will not process the input. Instead, the buttons will give the user options. For example: a SUBMIT button, so even if you hit enter on the last field, you can still make changes, and nothing will be processed until you click the SUBMIT button. There will also be a CANCEL, RESET and CHANGE buttons. CANCEL will end the program without any further processing; RESET will clear all the fields and you will have to enter all the field values again; CHANGE button will repeat the FIELD input process from the top, but leave the vaules in the input fields. If you want to keep the value, you can use the TAB key as the values will have already been committed.
This is a very basic screen input box, where it uses a non-graphical user interface, and from here you can take this data, build a record and write it to a file.
Code: Select all
/*
PROGRAM: Screen Input v3.0
Original program by ricardobytes
The Dutchman changes (some) used here
Modifications by George McGinn
This is a very basic screen input program, where it uses a non-graphical user interface, and from here you can take this data, build a record and write it to a file.
*/
Initialize:
prompt$=""
Answer$=""
SetupInputLabels:
PRINT "What is your name?"
FIELD "z" TEXT prompt$ AT 1,35 SIZE 300, 25
PRINT!PRINT!PRINT!PRINT "Where do you live?"
FIELD "y" TEXT prompt$ AT 1,128 SIZE 300, 25
PRINT!PRINT!PRINT!PRINT "How long have you been a Forum member?"
FIELD "x" TEXT prompt$ AT 1,214 SIZE 300, 25
PRINT!PRINT!PRINT!PRINT "What is your favorite feature of the Forum?"
FIELD "w" TEXT prompt$ AT 1,304 SIZE 300, 25
PRINT!PRINT!PRINT!PRINT "Have you posted any programs?"
FIELD "v" TEXT prompt$ AT 1,400 SIZE 300, 25
PRINT!PRINT!PRINT!PRINT "Results of input boxes:"!PRINT "-----------------------"
GetInput:
' Create Input Name input box & get value
FIELD "z" BACK COLOR 0,1,0
FIELD "z" FONT NAME "Courier"
FIELD "z" SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED("z")
FIELD "z" BACK COLOR 1,1,1
' Create Where Do You Live input box & get value
FIELD "y" BACK COLOR 0,1,0
FIELD "y" FONT NAME "Courier"
FIELD "y" SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED("y")
FIELD "y" BACK COLOR 1,1,1
' Create Forum Member input box & get value
FIELD "x" BACK COLOR 0,1,0
FIELD "x" FONT NAME "Courier"
FIELD "x" SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED("x")
FIELD "x" BACK COLOR 1,1,1
' Create Favorite Forum Feature input box & get value
FIELD "w" BACK COLOR 0,1,0
FIELD "w" FONT NAME "Courier"
FIELD "w" SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED("w")
FIELD "w" BACK COLOR 1,1,1
' Create Have You Posted input Box & get value
FIELD "v" BACK COLOR 0,1,0
FIELD "v" FONT NAME "Courier"
FIELD "v" SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED("v")
FIELD "v" BACK COLOR 1,1,1
GOSUB GetAnswers
STOP
'Get and print out all the results
'
'
GetAnswers:
Answer$=FIELD_TEXT$("z")
PRINT "What is your name: "&Answer$
Answer$=FIELD_TEXT$("y")
PRINT "Where do you live: "&Answer$
Answer$=FIELD_TEXT$("x")
PRINT "How long have you been a forum member: "&Answer$
Answer$=FIELD_TEXT$("w")
PRINT "Yes, "&Answer$&" is a nice feature."
Answer$=FIELD_TEXT$("v")
PRINT "Interesting: "&Answer$
RETURN