Using Version 12.1.10
I created a Dialog with an TextEdit field.
In the properties for the Text object, I set the "Numbers Only" property to True. All was fine until I needed to enter a negative number, got a message that only numbers could be entered as soon as I entered the minus sign.
I have the same result if I try to enter a decimal. Fractions are not allowed either.
I just tried to SetDialogObjectProperty to a negative and a fraction, and surprisingly they were both accepted correctly.
This cannot be intentional, it looks like a possible bug?
From the Help manual: " Allows only numbers to be typed into the text edit." Does this need to be changed to "Allows only positive integers to be typed into the text edit." ?
Cannot enter negatives or fractions in Dialog text object
Moderators: JRL, Dorian (MJT support)
- Dorian (MJT support)
- Automation Wizard
- Posts: 1414
- Joined: Sun Nov 03, 2002 3:19 am
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
All the dialog object properties are inherited from Delphi. This option literally means numbers only. Perhaps a better name would be digits only ... But the name was given by the delphi developers. Point being it literally means digits only so no minus signs or dots.
What I would recommend is to split the fields out into units, decimals And have a plus minus toggle in front. The units and decimal fields can be numbers only. This gives you good verification and avoids the user entering rubbish so avoids having to use code to check the input, and you can make it look quite pretty:
+/- [units] . [decimals]
The dot would just be a label. The plus or minus could be a drop down.
If you prefer a single text field you would need to NOT use numbers only option and add code in your script to verify the input.
What I would recommend is to split the fields out into units, decimals And have a plus minus toggle in front. The units and decimal fields can be numbers only. This gives you good verification and avoids the user entering rubbish so avoids having to use code to check the input, and you can make it look quite pretty:
+/- [units] . [decimals]
The dot would just be a label. The plus or minus could be a drop down.
If you prefer a single text field you would need to NOT use numbers only option and add code in your script to verify the input.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Or here's an example of some not so "pretty" but relatively simple code that keeps your dialog from getting congested. Any character you put in the "ListOfAcceptableCharacters" list will be acceptable. Any character not on the list will be unacceptable and rejected.Marcus wrote:...avoids the user entering rubbish so avoids having to use code to check the input, and you can make it look quite pretty:
The edit object property NumbersOnly is turned off. (set to False)
Code: Select all
VBStart
VBEnd
Dialog>Dialog1
object Dialog1: TForm
object Edit1: TEdit
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,Edit1,OnKeyPress,AcceptableCharactersTest
AddDialogHandler>Dialog1,Edit1,OnKeyUp,RemoveUnacceptableCharacters
LabelToVar>ListOfAcceptableCharacters,vData
Show>Dialog1,res
SRT>AcceptableCharactersTest
//Ignore backspace key
If>AcceptableCharactersTest_Key<>8
VBEval>chr(%AcceptableCharactersTest_Key%),char
Separate>vData,char,SepRes
If>SepRes_Count>1
Else
Let>RemoveFlag=1
EndIf
EndIf
END>AcceptableCharactersTest
SRT>RemoveUnacceptableCharacters
If>RemoveFlag=1
Let>RemoveFlag=0
GetDialogProperty>Dialog1,Edit1,text,EditStr
StringReplace>EditStr,Char,,EditStr
SetDialogProperty>Dialog1,Edit1,text,EditStr
SetDialogObjectFocus>Dialog1,Edit1
Press end
MDL>"%char%" is an unacceptable character.
EndIf
END>RemoveUnacceptableCharacters
/*
ListOfAcceptableCharacters:
1
2
3
4
5
6
7
8
9
0
-
+
*
/
*/