Page 1 of 1
How to limit the number of characters in a texbox
Posted: Mon Jun 18, 2018 2:18 am
by kullboys
Hello everyone
Trying to limit the number of characters a textbox can accept. There is no MaxLength property available. I have tried using the TextBox that comes through "Add Control" but it has no option to attach a tag. To summarize I am looking for a textbox control that can be attached to a tag and that has a MaxLength kind of property.
Thanks
.
Re: How to limit the number of characters in a texbox
Posted: Mon Jun 18, 2018 2:16 pm
by stasKanRich
hi,
not sure if this fixes your problem but you can do this by the validation section in the Analog numeric. it has lower limit and upper limit.
Re: How to limit the number of characters in a texbox
Posted: Mon Jun 18, 2018 2:26 pm
by stasKanRich
another idea.
create a new tag to have the "corected version"
so you will have two tags in your tags view:
yourOriginalTag ( data from where ever)
yourOriginalTag_corrected ( HMI tag will be changed by c#)
Code: Select all
int minNum = 12 ;
int maxNum = 123 ;
var origTag = Globals.Tags.yourOriginalTag ;
var cappedTag = Globals.Tags.yourOriginalTag_corrected;
if (Globals.Tags.yourOriginalTag.Value < minNum )
{
Globals.Tags.yourOriginalTag.Value = minNum ;
}
if (Globals.Tags.yourOriginalTag.Value > maxNum )
{
Globals.Tags.yourOriginalTag.Value = maxNum ;
}
use the corrected in the textbox
and call that from some periodic/timed function from the screen ?
Re: How to limit the number of characters in a texbox
Posted: Wed Jun 20, 2018 1:33 am
by wlederer
Hi, use script.
Globals.Tags.MyTag_rounded.Value =Math.Round((double)Globals.Tags.MyTag.Value,1);//rounds value to 1 decimal