Henko is an excellent programmer and designer. And his code not only shows you how to create a good looking input box, but some of the neat and powerful freatures SB offers you. But let me take you back to basics going back years when Henko, Rbytes, Dutchman and I worked on creating different methods to create input boxes.
Dutchman's Inline Input program is great for text games, or programs where the next input box is based on your answer to the previous question. An Example would be if you asked a person if they have a criminal record. If they say no, you display the next question. If they answer yes, then you may want to display a box or series of them to get more information on their crimes before going to the next question. This method leaves the screen looking much cleaner than putting all those extra input boxes out there when they may not be needed.
But if you have a standard set of inputs that do not require extra input, the following is what I came up with using what Rbytes originally came up with after Dutchman's Inline Prompt program. I took it to the next step where you see all the questions and incorporated the highlighted fields from Dutchman's Program.
This program was created many years ago, and there are other incarnations of it, but this is the simplest way to demonstrate how to line up input questions to output boxes, and even displays your responses after you hit enter on the last field. This also shows how you can highlight the current question you are on, which is handy if your screen is divided into sections and you have many inputs.
This was a combined effort where I took code from the Dutchman Inline and a program Rbytes wrote that also displayed each question one at a time to create a simple sample of displaying a screen, with all the inputs, and placing the cursor at the first field.
I'll have to look, but if you understand buttons and how this works, you can set up a submit button and instead of it executing the screen on hitting ENTER on the last field, you can redirect it back to the top, just in case you need to correct something. I have that program somewhere, I just need to find it.
You can also move between fields using the TAB buttons, but it does not move the highlighting. So if you tab ahead, the box above will stay highlighted. It does not effect the program, as a TAB will work and the answer you provide will be accepted.
You can accomplish highlighting with TABs, but you'll need to add code to know where you are. I have this in a program I'm still working on that converts files from JSON, XML and text, but it's not finished. It highlights the question you are on whether you use ENTER or the TAB keys.
I can see if I can just isolate how to move the highlight with the TAB or ENTER keys if you want. Or you can try it with this program yourself.
Also, I created a Function that executes a new command PRINTLINE that is handy if you have a lot of blank PRINT statements. PRINTLINE(5) will print five blank lines and makes your code look a little cleaner than having lines like: PRINT!PRINT!PRINT!PRINT!PRINT
This program is well commented, so I hope it helps as well.
Code: Select all
/*
PROGRAM: Screen Input v3.1
Original program by rbytes
The Dutchman changes from Inline used differently
Modifications by George McGinn
This program nows aligns the labels and FIELD TEXT so that the input boxes appear next to the question or label, thus reducing the number of lines needed on the screen (by 10).
I also introduced the TAB(N) option to the PRINT statement. This performs N number of tabs then prints the text that follows, starting on N tabs + 1 position. This is better than putting all those spaces in front of the text just to get them to align up.
Also, I created a new command - PRINTLINE(N). This is a simple function that, instead of typing 4 or 5 PRINT statements, I now only have to write one print and tell it how many blank lines I want. Your code can get very messy looking if you have tons of "PRINT!PRINT!PRINT!PRINT!PRINT" statements all over in conditional logic (IF/THEN/ESEIF statements).
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.
*/
SBMain:
prompt$=""
Answer$=""
SetupInputLabels:
PRINT!PRINT TAB(14);"What is your name:"
FIELD "z" TEXT prompt$ AT 380,30 SIZE 300, 25
PRINT!PRINT TAB(14);"Where do you live:"
FIELD "y" TEXT prompt$ AT 380,75 SIZE 300, 25
PRINT!PRINT "How long a member of the Forum:"
FIELD "x" TEXT prompt$ AT 380,120 SIZE 300, 25
PRINT!PRINT " Favorite feature of the Forum:"
FIELD "w" TEXT prompt$ AT 380,165 SIZE 300, 25
PRINT!PRINT " Have you posted any programs:"
FIELD "v" TEXT prompt$ AT 380,210 SIZE 300, 25
PRINTLINE(4)!PRINT "Results of input boxes:"!PRINT "-----------------------"
GetInput:
GET_INPUT("z")
GET_INPUT("y")
GET_INPUT("x")
GET_INPUT("w")
GET_INPUT("v")
GOSUB GetAnswers
STOP
GetAnswers:
'Get and print out all the results
'
'
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
DEF GET_INPUT(FIELD$)
FIELD FIELD$ BACK COLOR 0,1,0
FIELD FIELD$ FONT NAME "Courier"
FIELD FIELD$ SELECT
DO
SLOWDOWN
UNTIL FIELD_CHANGED(FIELD$)
FIELD FIELD$ BACK COLOR 1,1,1
ENDDEF
DEF PRINTLINE (A)
N=1
DO
PRINT
N+=1
UNTIL N > A
ENDDEF