Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Charater Limit for input

Author
Message
Great Knight
23
Years of Service
User Offline
Joined: 25th Feb 2003
Location:
Posted: 13th May 2003 05:54
Hey I am wondering how do I make a charater limit for the input command. I just cant figure this out.
AMD Atherlon 2400+ XP, 380 DDr memeory, ATI Radeon 9000 64 DDR.

And a Katana.
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 13th May 2003 21:55
dont use the input command for a start! write a routine that uses the entry buffer instead.. i have provided an example here

now ya mite ask why do it this way, well several reasons, the main one is that no matter how fast someone elses pc is or how fast they can type it will not miss anything they input, plus it gives ya more control over input

optic blast! megablast! have a blast!!
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 13th May 2003 21:57 Edited at: 14th May 2003 01:06
this post was removed by shwuckie thanx to the discovery of the edit post link lol the one after this is the important one.. if ya reading this still... may i ask why?? i told you read the next one! now... begone!

optic blast! megablast! have a blast!!
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 13th May 2003 22:31 Edited at: 14th May 2003 01:11
doh doh and err doh!! i made a slight mistake in the snippet i sent so here it is all fixed and working properly!! my bad... lol


sync on
mainloop:
text$=""
clear entry buffer
intext$=""
while intext$=""
cls
center text 320,50,"Enter your string"
` this will show the current input text before ya press enter
center text 320,100,text$
gosub CheckInput
`this will end loop if return was pressed after input was done
if sendmsg=1
intext$=text$
endif
sync
endwhile
cls
print "restarting loop"
sync
wait 1000
goto mainloop

` this is the subroutine you will call from another loop
CheckInput:
`this var holds the max length of the string to be entered
MaxLengthOfText=20
sendmsg=0
`read the current keyboard entry buffer, add to text$ var, clear the buffer
`get whatever has been typed from the windows entry buffer since this was last called
text$=text$+entry$()
`dont forget to clear it!!
clear entry buffer
`check for backspace
IF asc(right$(text$,1))=8
`and if backspace was pressed remove the backspace char and the previous char
IF LEN(text$)>0 THEN text$=LEFT$(text$,LEN(text$)-2)
endif
`check for enter key
if asc(right$(text$,1))=13
`drop the return char from the string so an empty string cant get passed
text$=LEFT$(text$,LEN(text$)-1)
`if text$ var is not empty let calling routine know text$ var is ready for use
if text$<>"" then sendmsg=1
endif
`this line limits the length of the string
if len(text$)>MaxLengthOfText then text$=left$(text$,MaxLengthOfText)
clear entry buffer
return

optic blast! megablast! have a blast!!
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 13th May 2003 22:37 Edited at: 14th May 2003 01:05
sorry its late im tired been a loooong day lol, gee i hope this helps in the long run! i think i will shut up now....

optic blast! megablast! have a blast!!
Kangaroo2
23
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 13th May 2003 23:03
shwuckie - Nice example man But I think you may have missed the lil links under your posts that say "edit this post"

It should also be added that alteranatively you can check the length of a string after it has been entered and if it is too large, ask again. But using the entry buffer is a prefered (If more difficult for a beginner) technique

Coming Soon! Kangaroo2 Studio... wait and quiver with anticipation! lol
[email protected] - http://www.kangaroo2.com - If the apocalypse comes, email me
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 14th May 2003 01:01 Edited at: 14th May 2003 01:09
well waddayaknow!!! ya right i didnt see the edit this post thingo, oops ! me again lol and hey Kangaroo2, i noticed you joined the forums on my 30th birthday, do i get a present??? lol

optic blast! megablast! have a blast!!
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 14th May 2003 11:13 Edited at: 14th May 2003 11:15
well today is another day and after having some sleep, my brain started working again, so heres the FUNCTION version of the above snippet, easier to read and less hassle to implement



groovy!

optic blast! megablast! have a blast!!
Kangaroo2
23
Years of Service
User Offline
Joined: 26th Sep 2002
Location: United Kingdom
Posted: 14th May 2003 12:02
nice work! And as a present I won't ummmmm.... do something nasty 2 u. Ther u go, that'll do, its to early in the morning to think something up

Coming Soon! Kangaroo2 Studio... wait and quiver with anticipation! lol
[email protected] - http://www.kangaroo2.com - If the apocalypse comes, email me
shwuckie
23
Years of Service
User Offline
Joined: 9th May 2003
Location: Australia
Posted: 14th May 2003 18:20
thats good lol had enuff of that nasty stuff x-d now i guess i have another late night trying to sort out my own db pro problems!

optic blast! megablast! have a blast!!

Login to post a reply

Server time is: 2026-07-11 12:03:04
Your offset time is: 2026-07-11 12:03:04