Cannot enter negatives or fractions in Dialog text object

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
obfusc88
Pro Scripter
Posts: 85
Joined: Wed Mar 14, 2007 6:22 pm

Cannot enter negatives or fractions in Dialog text object

Post by obfusc88 » Mon Aug 12, 2013 6:46 am

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." ?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1350
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Tue Aug 13, 2013 12:07 am

This one is out of my realm of experience, and Marcus is out of the office for a few more days. We'll make sure he is aware of this upon his return.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Aug 20, 2013 9:12 am

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Aug 20, 2013 7:20 pm

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:
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.

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
-
+
*
/
*/

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts