Thanks for the suggestions, but unfortunately it doesn't seem to be anywhere near that easy. A user can put the insertion point within a number and so I need to check before the character is entered whether the value will be a number after the new character is added at the insertion point. The new character may be at the start of a numeric string, in the middle or at the end. I can't find an easy function that gives the insertion point relative to the selectedLine. Most of the complexity of my script is in deciding where the insertion will be made in the line of interest.

Still lacking a simple solution...

At 8:56 PM -0500 26/10/05, [EMAIL PROTECTED] wrote:
the isNumber of value
isNumber(value)

isNumber(8) -- returns true
isNumber(1+5) -- returns true
isNumber(foo) -- returns false

Dennis

Thanks, but the 'isnumber' function is the same as the 'is a number' that I used in my script.


At 8:56 PM -0500 26/10/05, [EMAIL PROTECTED] wrote:
You can also add zero to it; if it is a number then the result will be
empty.
Paul Looney

Thanks, but that is not functionally different from simply using 'is a number'. Or is it?

At 10:34 AM +1000 27/10/05, Michael J. Lew wrote:
How can I prevent users from being able to make non-number values in a field? Simply preventing non-numeric keys is not enough because I need to prevent things that use characters that are in valid numbers to make non-numbers like 1.2.3 or -1.2-3.

I thought it would be relatively easy, but it might not be. Here is the field script of a surprisingly complicated attempt:

on keydown thekey
  if theKey is in "0123456789-." then --may be an allowable input
    -- but I still need to check whether the result would be a valid number.
    put value(the selectedLine) into thisLine --current number
    put length(thisLine) into thisLineLen
put the selectedCHunk into sc --returns character locations from start of field --Need to find where the current line starts
    put offset(thisLine,me,min(0,word 2 of sc-thislinelen)) into thisLineStart
    --The characters to skip bit is an attempt to prevent the offset function
    --  from returning a match to an earlier line in the field.
    --  It needs the min function to prevent negative values.
--Now see if the input would make a non-numeric result
    --First find where the selection point is in the line
    put word 2 of sc +1 - thisLineStart into theSelectionStartChar
    put word 4 of sc +1 - thisLineStart into theSelectionEndChar
    --I don't know why I had to add one to the values...
    put thisLineStart & return & theSelectionStartChar && theSelectionEndCHar
    --Now test the input in the relevant place
put theKey into char theSelectionStartChar to theSelectionEndChar of thisLine --next line to help debugging --put thisLine & return & thisLineStart & return & theSelectionStartChar && theSelectionEndChar if thisLine & "0" is a number then --should be OK
      --Needs the appended zero to allow a line to start with a decimal point.
      pass KeyDown
    end if
  end if
end keydown


It seems to work, but it's an extraordinarily long and winding road to get to a simple end-point. What am I missing?

Thanks,
Michael



--
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: [EMAIL PROTECTED]
**
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to