You could add a space to the actual input but if the user hits backspace he/she would have to back up the automatically added spaces. It's better to keep the user input without spaces but show the user the same input with spaces every 4 characters. That way when they do backspace it'll erase only the characters entered and not the spaces.
` The input string
InpStr$ = ""
` Set the max number of characters in the string
MaxLength=16
inputxpos=500
CLEAR ENTRY BUFFER
` Make background of text fill in too
set text opaque
do
`Handle input
char$ = entry$()
clear entry buffer ` Always clear buffer after getting entry$()
` Clear Temp$ and the count
Temp$="":Count=0
` Go through each character in InpStr$
for t=1 to len(InpStr$)
` Add one character to Temp$
Temp$=Temp$+mid$(InpStr$,t)
` Increase the count
inc Count
` Check if it's time to add a space between code boxes
if Count=4
` Add the space
Temp$=Temp$+" "
` Reset the count
Count=0
endif
next t
` Show what the user sees
text 0,0,"What the user sees: "+Temp$+" "
` Show the actual input
text 0,40,"What the actual input is: "+InpStr$+" "
select asc(char$)
case 8 : `Backspace
InpStr$ = left$(InpStr$, len(InpStr$) - 1)
endcase
` Check for return
case 13:
` Leave the DO/LOOP
exit
endcase
case default
` Check if the length of InpStr$ is less than the max length
if char$<>"" and len(InpStr$)<MaxLength
InpStr$ = InpStr$ + char$
endif
endcase
endselect
loop
` Check if the code is valid (make Code equal the number returned from the CodeCheck() function
Code=CodeCheck(InpStr$)
` Show if it's a vaid code or not
if Code=0
text 0,100,"Invalid Code"
else
text 0,100,"Valid Code"
endif
wait key
` Always END before the first function to prevent an error
end
` Check to see if the code is valid
function CodeCheck(Code$)
` Do whatever checks you need on Code$ (which is InpStr$ outside this function)
Valid=rnd(1) ` Pick a zero or a one (till you add vaildation code)
` if Valid=0 the Code is not valid
` if Valid=1 the code is valid
` Leave the function returning the variable Valid
endfunction Valid
What the above does is shows both what you want the user to see Temp$ and the actual input InpStr$. The Temp$ is the one the spaces are added to using a counter so the actual input remains intact. I also added char$<>"" to the check for the max length because when I ran your code as it was it automatically put the length at 19 and thus I couldn't input anything.
I also saw a GOTO in there to check if the code was valid... it's best to avoid GOTO altogether (now that you know how it works). Instead of using GOTO to leave the DO/LOOP you can use EXIT to go to the line right after LOOP.
At the bottom of the code snip I added a function for you to use for the code check so you can see how a function would work. All you have to do is make Valid=0 if the code isn't valid or Valid=1 if it is valid.