Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 need a way to limit the how many characters a user can type? =)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AiShiDeSu




PostPosted: Thu Jan 14, 2010 9:59 pm   Post subject: need a way to limit the how many characters a user can type? =)

What is it you are trying to achieve?

OKAII well here's the thing
i'm trying to make a program that will record the user's name and the highest score they get on my game

and i used a get command

HOWEVER, since i wanted to dummy proof it, i want it limited to around maybe 10 character
so the users can't type in something like "asofasgfuoasgofgasog" that messes up my program

I asked my teachers and he had NO idea O.o
so uh, please help? :3
any code that can limit inputting characters?



What is the problem you are having?

i don't know any code for it >_<

Describe what you have tried to solve this problem

well my i looked up turing references and tried

var answer : string (10)

but it didn't work D;


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

noo, just a simple get one


Please specify what version of Turing you are using
i am using 4.1.1 i think =D

THANKS IN ADVANCE ;D
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Thu Jan 14, 2010 10:05 pm   Post subject: RE:need a way to limit the how many characters a user can type? =)

Get input one character at a time using getch. Look it up in the turing documentation if you don't know how to use it. To get to documentation, in Turing hit F10, and use search to find the documentation for getch.
Carey




PostPosted: Thu Jan 14, 2010 10:16 pm   Post subject: RE:need a way to limit the how many characters a user can type? =)

You could also do a

code:

loop
    get name
    exit when name len <= 10
    put "Sorry, 10 chars is the limit for a name"
end loop


Kind of structure
Euphoracle




PostPosted: Thu Jan 14, 2010 10:55 pm   Post subject: RE:need a way to limit the how many characters a user can type? =)

Alternatively,

get name : *
name := name(1..10)
AiShiDeSu




PostPosted: Sat Jan 16, 2010 3:29 pm   Post subject: Re: RE:need a way to limit the how many characters a user can type? =)

Carey @ Thu Jan 14, 2010 10:16 pm wrote:
You could also do a

code:

loop
    get name
    exit when name len <= 10
    put "Sorry, 10 chars is the limit for a name"
end loop


Kind of structure


Would you declare len as a string, int, char or char of boolean? =)
Kharybdis




PostPosted: Sat Jan 16, 2010 5:04 pm   Post subject: Re: RE:need a way to limit the how many characters a user can type? =)

AiShiDeSu @ Sat Jan 16, 2010 3:29 pm wrote:
Carey @ Thu Jan 14, 2010 10:16 pm wrote:
You could also do a

code:

loop
    get name
    exit when name len <= 10
    put "Sorry, 10 chars is the limit for a name"
end loop


Kind of structure


Would you declare len as a string, int, char or char of boolean? =)

that would be an int..
DtY




PostPosted: Sat Jan 16, 2010 10:45 pm   Post subject: RE:need a way to limit the how many characters a user can type? =)

This is probably more what you're looking for, it will just prevent you from entering more characters. Note that this will stop the backspace from properly working, and you wont be able to use the arrow keys to change the cursor position, but you can add that in if you want to in the future.

Sorry, I don't know how I can describe this, so I'm posting the code (shouldn't be a problem, since it's a small part of a project, and not a single complete program)

Turing:
function get_charLimit(length:nat)
    var entered:string
    var enteredLength:nat
    var key:string(1)

    loop
        getch(key)
        if key = "\n" then %User pressed enter
            exit
        else
            entered += key
            enteredLength += 1
        end if

        exit when enteredLength >= length
    end loop

    return entered
end get_charLimit


I don't have a computer with Turing, so there might be (and probably is) an error in there, but that's the idea.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: