Numeric Textbox input only with the permitted punctuation marks (period, comma, minus)

Hi,
I created a textbox event handler to only allow my textboxes to
accept numbers only with three permitted punctuation marks:
period (decimal), comma and minus (substract).
The script contains five text fields.
>>>The first of the three text fields should behave exactly as
spinners do. The conditions are as follows:
-TB_Spiner1 [minimum:0 ; maximum:1000 ; decimal Places:3] [FloatValue]
-TB_Spiner2 [minimum:1 ; maximum:100 ; decimal Places:0] [IntegerValue]
-TB_Spiner3 [minimum:-200 ; maximum:200 ; decimal Places:2] [FloatValue]
-*MouseWheel* Increment are 1 (when hold CTRLKey Increment are 10)
-*KeyArrows* (Up and Down) Increment are always 1 (one).
-*Escape* Key reset a value to the default
-*Return* Key executes and checks if the value is in acceptable limits.
-*Tab* Key select next active control in form.
I also allow to input *minus* only if selection start at the
beginning, and *Period* can be set only once. (for floats)

>>>Description and Conditions for the fourth text field:
*TB_valueInput1*: Fill the text filds with the numbers
[Float or Integer] while the sum are not > 300.
If the last entry exceeds the maximum (300) then it will be
deleted after you press *Return* key.
Allowed punctuation marks: (period, comma, minus).*Space* between the numbers are disallowed.
NOTE: The input must be *in one direction* i.e. all numbers must have either a positive or negative values e.g.([-10,-20,-30,] or [10,20,30,],so that the absolute value of the sum is greater than three hundred [abs(theSum) < 300]. Three hundred is the limit.
-*Escape* Key clear text field.
-*Return* Key executes and checks if the value is in acceptable
limits.
-*Tab* Key select next active control in mxsForm.

>>>Description and Conditions for the fifth text field:
*TB_valueInput2*: Fill the text filds with the positive and negative numbers [Float or Integer].Only limitation is:
the value of a number must be in range [min:-90 ; max:90].
If the value is greater than the allowed range then is replaced by zero when press *Return* key.
-*Escape* Key clear text field.
-*Return* Key executes and checks if the value is in acceptable limits.
-*Tab* Key select next active control in mxsForm.

I have several questions:
1. Is there an easier and better way to solve this? (show some example)
2. When i press (CTRL+V) or (RMB and Paste from contex menu) how to put Clipboard text through filter functions (from this script *fn numConvert* or *fn summerize*) before it is displayed in the text field.
I almost started to explore possibilities of .NET integration in maxscript.
Any ideas and suggestions are welcome! Thank you in advance and sorry for my english.
Branko

AttachmentSize
numeric_textbox_input.zip3.86 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

TsveTan are you try a script

TsveTan are you try a script in attachment. I allready add theses
funkcions and it's works fine.
All textboxes in the form will perform some action.
For example:
Spinner1 [spnTB1] (changing the distance)
Spinner2 [spnTB2] (changing the count)
Spinner3 [spnTB3] (changing the angle)
valueInput1 [valTB1] (translation Z coordinats)
valueInput2 [valTB2] (different angles at a certain distance)
This is only a test script. That's the thing.
Thanks for the heads-up.

barigazy

TsveTan's picture

""

... or put to the case expression a default condition and return the text to the initial state.

TsveTan's picture

""

You dont need to specify the numeric keys, decimal and so on, if you are not looking for a specific action to be performed, when they are pressed on the keyboard (sorry, I have not read carefuly your main description). By default textboxes are controls which accept most keys. To understand me right I will say a button is able to "listen" only several key strokes. You can test it with a print test like "Enter was pressed" in the keyeventarg condition - result body of the keyDownFn. To exclude some keys you should use a filter (as you say).
You can filter lower,upper keys with the character casing property:
sample: mytextbox.charactercasing = mytextbox.charactercasing.lower
I think there isnot a characterfilter property for textboxes.
You can write a filter. Everytime a key is pressed the keyDown function executes and the filter will delete unwanted characters.
sample:

-- a variable, that stores the last correct textbox string
mycorrectstring = mytextbox.text
--This is in the body of keDownFn
args = #((arg.keycode.D0),(arg.keycode.D1)...(arg.keycode.enter))
-- a condition that returns the last correct string, if an unallowable key is pressed.
for i = 1 to args.count do
(if arg.keycode != args[i] do mytextbox.text = mycorrectstring else mycorrectstring = mytextbox.text)
--Maybe there is more professional solution , but this works.
barigazy's picture

Hi,TsvetanThanks for the

Hi,Tsvetan

Thanks for the reply.
Your suggestions are excellent.
If I understood you well, then in addition to these (Enter,Tab,Esc...)i must add all numerics as well and punctuation marks (e.g. arg.keycode.D1 ; arg.keycode.D2 ; arg.keycode.D3...
arg.keycode.Decimal ; arg.keycode.Supstract etc.)
What do you think about the functions of filtering text input
(fn numConvert and fn summerize).Whether they are in general required
or there is some better solution.
Do you have any suggestion for 2nd question?

barigazy

TsveTan's picture

Basically ...

Create a dotNet form myform.

myform.keypreview = true
dotnet.addeventhandler myform "activated" (fn ac obj arg = (enableAccelerators = false))
dotnet.addeventhandler myform "deactivate" (fn deac obj arg = (enableAccelerators = true))
...
-- and for the textbox you need keyDown eventargs:
...
fn keyDownFn obj arg =
(
 case arg.keycode of
 (
 (arg.keycode.tab):( ... do something ...)
 (arg.keycode.enter):(... do something ...)
  ...
 )
)
dotnet.addEventHandler mytextbox "keydown" keyDownFn
-- keys are acceptable, only if the control is focused.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.