Wednesday, January 24, 2018

#1 2006-06-10 11:27:12 am

hendo13
Member
From:: Barrie, Ontario
Registered: 2006-06-05
Posts: 542
Website

max character length in prompt

hey I was just wondering how you can make it so when your prompt comes up it only allows the user to type a set maximum number of characters. thnx!:)


That was a message from Hendo!

Offline

 

#2 2006-06-10 01:02:32 pm

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4660

Re: max character length in prompt

You can control how many characters you accept, but not how many they type in.

You could indicate the length crudely and then grab the first part thus:

Applescript:

set sp to ""
repeat 30 times
   set sp to sp & "n"
end repeat
set sp to "|" & sp & "|"

set ans to text returned of (display dialog "Your answer should fit above the second line" default answer "" & return & sp)
set o to text 1 thru ((offset of "|" in ans) - 1) of ans


iMac running OS X 10.13.1

Offline

 

#3 2006-06-10 04:51:26 pm

Cuneyt Ocaklilar
Member
From:: Istanbul, Turkey
Registered: 2002-11-20
Posts: 56

Re: max character length in prompt

Or, something like this:

Applescript:

repeat
   set ans to text returned of (display dialog "Your answer should be maximum 30 characters long" default answer "")
   if length of ans is not greater than 30 then exit repeat
end repeat


Cuneyt Ocaklilar

Offline

 

#4 2006-06-10 05:05:27 pm

kai
Member
From:: Brighton, UK
Registered: 2005-05-28
Posts: 912

Re: max character length in prompt

A repeat loop could also be used to propose a truncation of any answer that's too long:

Applescript:

to get_answer to q for n
   set a to ""
   repeat
       set a to text returned of (display dialog q & return & "(maximum " & n & " characters)" default answer a)
       if a's length is not greater than n then return a
       set a to a's text 1 thru n
   end repeat
end get_answer

get_answer to "Please enter some text." for 30


kai

Offline

 

#5 2006-06-10 05:37:19 pm

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4660

Re: max character length in prompt

Or with just a wee mod to change the question:

Applescript:

to get_answer to q for n
   set a to ""
   repeat
       set a to text returned of (display dialog q & return ¬
           & "(maximum " & n & " characters)" default answer a)
       if a's length is not greater than n then return a
       set a to a's text 1 thru n
       set q to "Would this much be Okay?"
   end repeat
end get_answer

get_answer to "Please enter some text." for 10

{I changed the limit to 10 for easier illustration}


iMac running OS X 10.13.1

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)