Author |
Message |
tjmoore1993
|
Posted: Mon Apr 27, 2009 7:04 pm Post subject: [Help] Get Statements |
|
|
What is it you are trying to achieve?
I am trying to get a reply from a user but only limiting them to entering a max of 8 characters.
Describe what you have tried to solve this problem
Honestly, I was not able to try things because I had no clue where to start.
Please specify what version of Turing you are using
I am using version 4.xx
To summarize this, If it is possible to stop input after a certain ammount of characters. Please share what you know.
Example:
Rodney buttface < This is 15 characters long
I want this
Rodney b < 8 characters long |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon Apr 27, 2009 7:12 pm Post subject: RE:[Help] Get Statements |
|
|
read up documentation on get
Although that will not prevent them from typing more than 8 characters, just the reading part (and the rest will be left over in a buffer).
Alternatively you could write your own read-buffer loop with getch |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tjmoore1993
|
Posted: Mon Apr 27, 2009 7:38 pm Post subject: RE:[Help] Get Statements |
|
|
Problem solved thanks to Tony's excellent resourcing skills.
Turing: |
setscreen ("graphics")
var name : string := ""
var x : int := 0
procedure getKey
var ch : string (1)
getch (ch )
name + = ch
cls
end getKey
for i : 1 .. 8
x := x + 1
locate (1, x )
getKey
put name
end for
|
|
|
|
|
|
|
Tony
|
Posted: Mon Apr 27, 2009 7:43 pm Post subject: RE:[Help] Get Statements |
|
|
bonus Tonys-approval points will be given out for implementing the use of backspace |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
tjmoore1993
|
Posted: Mon Apr 27, 2009 8:06 pm Post subject: Re: RE:[Help] Get Statements |
|
|
I will work on it a bit more. That was just a simple fix |
|
|
|
|
|
Euphoracle
|
Posted: Mon Apr 27, 2009 10:08 pm Post subject: RE:[Help] Get Statements |
|
|
Problem now is that people can't back-space errors, right? |
|
|
|
|
|
Tony
|
Posted: Mon Apr 27, 2009 10:23 pm Post subject: RE:[Help] Get Statements |
|
|
and that one would have to type out a bunch of spaces, to enter a word less than 8 characters. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Dusk Eagle
|
Posted: Mon Apr 27, 2009 10:31 pm Post subject: Re: [Help] Get Statements |
|
|
How about this Tony?
Turing: |
var name : string := ""
var x : int := 0
const BACKSPACE := 8
fcn getKey (word: string): string
var ch : string (1)
getch (ch )
cls
if ord(ch ) = BACKSPACE then
result word (1.. length(word )- 1) %returns all letters in word except the last one.
else
result word+ch
end if
end getKey
loop
exit when length(name ) = 8
locate (1, length(name )+ 1)
name := getKey (name )
put name
end loop
put name
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Mon Apr 27, 2009 10:54 pm Post subject: RE:[Help] Get Statements |
|
|
Crashes the program if you try to backspace on an empty string. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Dusk Eagle
|
Posted: Mon Apr 27, 2009 11:01 pm Post subject: Re: [Help] Get Statements |
|
|
Well that's not hard to fix:
Turing: | var name : string := ""
var x : int := 0
const BACKSPACE := 8
fcn getKey (word : string) : string
var ch : string (1)
getch (ch )
cls
if ord (ch ) = BACKSPACE then
if length (word ) = 0 then
result word
else
result word (1 .. length (word ) - 1) %returns all letters in word except the last one.
end if
else
result word + ch
end if
end getKey
loop
exit when length (name ) = 8
locate (1, length (name ) + 1)
name := getKey (name )
put name
end loop
|
Are there any other errors with this program? Because I can't find any. |
|
|
|
|
|
Tony
|
|
|
|
|
tjmoore1993
|
Posted: Tue Apr 28, 2009 2:20 pm Post subject: Re: [Help] Get Statements |
|
|
Dusk Eagle @ Mon Apr 27, 2009 11:01 pm wrote: Well that's not hard to fix:
Turing: | var name : string := ""
var x : int := 0
const BACKSPACE := 8
fcn getKey (word : string) : string
var ch : string (1)
getch (ch )
cls
if ord (ch ) = BACKSPACE then
if length (word ) = 0 then
result word
else
result word (1 .. length (word ) - 1) %returns all letters in word except the last one.
end if
else
result word + ch
end if
end getKey
loop
exit when length (name ) = 8
locate (1, length (name ) + 1)
name := getKey (name )
put name
end loop
|
Are there any other errors with this program? Because I can't find any.
Error:
You can not backspace when max characters are entered.
Request:
If possible could you make it work so if the key enter is pushed it will do an action but still maintain that 8 char limit.
This really means a lot! |
|
|
|
|
|
|