[bb] Simple input function by DougUK [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Simple input function
Author : DougUK
Posted : 1+ years ago

Description : To call the function just add:
inputText$=string_input$(aString$,20,100,150)  ; string,numberOfLetters,x,y

Handy for name input, text chat etc!


Code :
Code (blitzbasic) Select
Function string_input$(aString$,n,x,y)
Repeat
 If value=0 Then
length=Len (aString$)
If length>n-1 Then
Return aString$
Exit
EndIf
While Not value
value=GetKey()
Wend
If value=13 Then ; enter key
Return aString$
Exit
EndIf
If KeyDown (29) And value>0 Or KeyDown(157) And value>0 Then ; catch control keys
value=0
Else
If value>0 And value<7 Or value>26 And value<32 Or value=9 Then ;catch unwanted keys
value=0
Else
If value=8 Then ;backspace key
If length>0 Then
aString$=Left$ (aString$, length-1)
EndIf
Cls
Text x,y, aString$
value=0
Else
aString$=aString$+Chr$ (value)
Cls
Text x,y, aString$
value=0
EndIf
EndIf
EndIf
EndIf
Forever
End Function


Comments : none...