Macro Wizard / Form >> TextField Limit to a number range?

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Macro Wizard / Form >> TextField Limit to a number range?

Postby Robertspark » Thu Mar 14, 2019 9:44 pm

Odd ball question----

Macro Wizard / Form >> TextField Limit to a number range?

I know how to limit a textfield to 2 digits and I know how to limit to numbers only.

But, is there a way to limit the typed range to say 0-12??

Thanks,
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2109, Neuron Lite
UCCNC v1.2108 Macro Manual
Robertspark
 
Posts: 1330
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Vmax549 » Thu Mar 14, 2019 10:13 pm

Set up text box validation and then define your parameters.

Just a thought, (;-) TP
Vmax549
 
Posts: 41
Joined: Sun Nov 22, 2015 3:25 am
Location: USA

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Robertspark » Thu Mar 14, 2019 10:22 pm

Well I got this far:

Code: Select all
   void textBox1_KeyPress(object sender, KeyPressEventArgs e)
      {
         if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) )
         {
            e.Handled = true;
         }
      }
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2109, Neuron Lite
UCCNC v1.2108 Macro Manual
Robertspark
 
Posts: 1330
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Vmax549 » Thu Mar 14, 2019 10:35 pm

Textbox validation is your friend ;)

private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (textBox1.Text != "something")
e.Cancel = true;
}
Vmax549
 
Posts: 41
Joined: Sun Nov 22, 2015 3:25 am
Location: USA

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Dan911 » Thu Mar 14, 2019 11:04 pm

Hmmm, don't think you answered his question.

Don't let textbox value > 12. I have a routine but want to see what you come up with first. Don't worry about posting something silly you can just delete.
Dan911
 
Posts: 570
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Robertspark » Thu Mar 14, 2019 11:17 pm

The validating didn't work

I've had a few goes along the lines of:

Code: Select all
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                if (textBox1.Text == "0" || textBox1.Text == "1" || textBox1.Text == "3")
                {
                    e.Handled = true;
                }
            }
        }



Code: Select all
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                int i = Convert.ToInt32(textBox1.Text);
                if (i >=0 && i >= 12)
                {
                    e.Handled = true;
                }
            }
        }
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2109, Neuron Lite
UCCNC v1.2108 Macro Manual
Robertspark
 
Posts: 1330
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Robertspark » Thu Mar 14, 2019 11:23 pm

I guess I could always use a numeric UP Down control....
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2109, Neuron Lite
UCCNC v1.2108 Macro Manual
Robertspark
 
Posts: 1330
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Robertspark » Thu Mar 14, 2019 11:25 pm

I'll use the numeric up down it will meet my needs easier for what I want to do
Rob
Einstein ― “If you can't explain it to a six year old, you don't understand it yourself”
...working my way through the 1000+ ways things don't work to find the one that does
UC400eth, UC300eth, UCCNC v1.2109, Neuron Lite
UCCNC v1.2108 Macro Manual
Robertspark
 
Posts: 1330
Joined: Sat Sep 03, 2016 4:27 pm
Location: Nr Liverpool, England

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Dan911 » Thu Mar 14, 2019 11:31 pm

Hey Rob, possibly only allowing digits and using index of textbox and add should work

textBox.Text.Substring(index, 0) + textBox.Text.Substring(index, 1)

of course do your conversions along the way.
Dan911
 
Posts: 570
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Re: Macro Wizard / Form >> TextField Limit to a number range

Postby Dan911 » Fri Mar 15, 2019 7:31 am

Just wanting to limit value in textbox 0-12 you can just use the textbox MaxLength property for char amount and set to 2 and just check for 11. If allowing a decimal it can get a little more tricky.
Code: Select all
textbox.MaxKength = 2;
Dan911
 
Posts: 570
Joined: Mon Oct 31, 2016 1:22 am
Location: USA

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 3 guests