locked
Timer Interval Limit RRS feed

  • Question

  • What is the Maximum Timer Interval ?
    Friday, September 12, 2014 2:53 PM

Answers

  • A "&" character in the mask will allow all the characters you want to allow plus some that you don't want to allow. If you set the mask to "&&&&" the user can enter four characters, but they may include characters you don't want to allow. You can handle the Validating event (which fires when the user attempts to leave the textbox) and use that to really make sure that all the characters are allowed. The event handler can also force the cursor to remain in the textbox (using e.Cancel = True) if you detect an error.

    Private Sub MaskedTextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MaskedTextBox1.Validating
        For Each textChar As Char In MaskedTextBox1.Text
            If Not Char.IsLetter(textChar) And textChar <> "/" And textChar <> "\" Then
                e.Cancel = True
                MessageBox.Show("Enter only letters or slashes")
                Exit Sub
            End If
        Next
    End Sub
    

    Of course if you are doing this, there isn't much point using a MaskedTextBox, and you might want to use just a regular TextBox.

    • Marked as answer by Arshia Aghaei Saturday, September 13, 2014 6:51 PM
    Saturday, September 13, 2014 6:15 PM
  • The easiest way to find an answer to this type of question is to look in the documentation in the MSDN Library. The documentation for Windows.Timer.Forms.Interval is at msdn.microsoft.com/en-us/library/system.windows.forms.timer.interval(v=vs.110).aspx. It specifies that Interval is an Integer that represents milliseconds (thousandths of a second). As no other limit on Interval is documented, the limit is the maximum value of an Integer, which is about 2 billion. An Interval of 2 billion would be 2 million seconds.
    • Proposed as answer by IronRazerz Friday, September 12, 2014 2:59 PM
    • Edited by Blackwood Friday, September 12, 2014 3:02 PM spelling
    • Marked as answer by Arshia Aghaei Friday, September 12, 2014 3:12 PM
    Friday, September 12, 2014 2:58 PM
  • To do that you would need to allow 10 digits in the MaskedTextBox (which allows almost 10 billion) and then check that the value is not too big for an Integer using something like Integer.TryParse to convert the String to an Integer value.

    Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	maskedTextBox1.Mask = "0000000000"
    End Sub
    	
    Sub Button1_Click(sender As Object, e As EventArgs) Hanndles Button1.Click
    	Dim intvl As Integer 
    	If Not Integer.TryParse(maskedTextBox1.Text, intvl) Then
    		MessageBox.Show("Invalid Integer")
    		Exit Sub 
    	Else
    		MessageBox.Show(intvl.ToString("N0"))
    	End If
    End Sub
    

    • Marked as answer by Arshia Aghaei Saturday, September 13, 2014 3:52 PM
    Friday, September 12, 2014 3:35 PM

All replies

  • The easiest way to find an answer to this type of question is to look in the documentation in the MSDN Library. The documentation for Windows.Timer.Forms.Interval is at msdn.microsoft.com/en-us/library/system.windows.forms.timer.interval(v=vs.110).aspx. It specifies that Interval is an Integer that represents milliseconds (thousandths of a second). As no other limit on Interval is documented, the limit is the maximum value of an Integer, which is about 2 billion. An Interval of 2 billion would be 2 million seconds.
    • Proposed as answer by IronRazerz Friday, September 12, 2014 2:59 PM
    • Edited by Blackwood Friday, September 12, 2014 3:02 PM spelling
    • Marked as answer by Arshia Aghaei Friday, September 12, 2014 3:12 PM
    Friday, September 12, 2014 2:58 PM
  • The easiest way to find an answer to this type of question is to look in the documentation in the MSDN Library. The documentation for Windows.Timer.Forms.Interval is at msdn.microsoft.com/en-us/library/system.windows.forms.timer.interval(v=vs.110).aspx. It specifies that Interval is an Integer that represents milliseconds (thousandths of a second). As no other limit on Interval is documented, the limit is the maximum value of an Integer, which is about 2 billion. An Interval of 2 billion would be 2 million seconds.
    Wow!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 Billion ?!!!!!! And how to set the 2 Billion limit for a MaskedTextBox ?!!!!!!!!!
    Friday, September 12, 2014 3:14 PM
  • To do that you would need to allow 10 digits in the MaskedTextBox (which allows almost 10 billion) and then check that the value is not too big for an Integer using something like Integer.TryParse to convert the String to an Integer value.

    Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	maskedTextBox1.Mask = "0000000000"
    End Sub
    	
    Sub Button1_Click(sender As Object, e As EventArgs) Hanndles Button1.Click
    	Dim intvl As Integer 
    	If Not Integer.TryParse(maskedTextBox1.Text, intvl) Then
    		MessageBox.Show("Invalid Integer")
    		Exit Sub 
    	Else
    		MessageBox.Show(intvl.ToString("N0"))
    	End If
    End Sub
    

    • Marked as answer by Arshia Aghaei Saturday, September 13, 2014 3:52 PM
    Friday, September 12, 2014 3:35 PM
  • To do that you would need to allow 10 digits in the MaskedTextBox (which allows almost 10 billion) and then check that the value is not too big for an Integer using something like Integer.TryParse to convert the String to an Integer value.

    Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    	maskedTextBox1.Mask = "0000000000"
    End Sub
    	
    Sub Button1_Click(sender As Object, e As EventArgs) Hanndles Button1.Click
    	Dim intvl As Integer 
    	If Not Integer.TryParse(maskedTextBox1.Text, intvl) Then
    		MessageBox.Show("Invalid Integer")
    		Exit Sub 
    	Else
    		MessageBox.Show(intvl.ToString("N0"))
    	End If
    End Sub
    

    How to set only string characters for a MaskedTextBox ?
    Saturday, September 13, 2014 4:31 PM
  • I'm not sure what you mean by "only string characters"; all input is a String. Do you mean only alphabetic characters? An "L" in the mask represents a required alphabetic character and a "?" represents an optional alphabetic character. So the following would allow 1 to 3 alphabetic characters.

    maskedTextBox1.Mask = "??L"

    There are lots of other options you can use when setting up the mask. They are all documented in the MSDN library at msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask(v=vs.110).aspx

    Saturday, September 13, 2014 4:46 PM
  • I'm not sure what you mean by "only string characters"; all input is a String. Do you mean only alphabetic characters? An "L" in the mask represents a required alphabetic character and a "?" represents an optional alphabetic character. So the following would allow 1 to 3 alphabetic characters.

    maskedTextBox1.Mask = "??L"

    There are lots of other options you can use when setting up the mask. They are all documented in the MSDN library at msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask(v=vs.110).aspx

    Only Alphabetic & "\" & "/" Characters.
    Saturday, September 13, 2014 4:49 PM
  • Check the library page I linked to. There is no option that allows only alphabetic characters and slashes. The only options I can think of are:

    • Use a "C" or "&" in the mask to allow any character except a control character (like vbLF) and validate what the user entered in the textbox's LostFocus event.
    • Use a TextBox instead of a MaskedTextBox and test each character the user enters in the TextChanged event.
    Saturday, September 13, 2014 5:09 PM
  • Check the library page I linked to. There is no option that allows only alphabetic characters and slashes. The only options I can think of are:

    • Use a "C" or "&" in the mask to allow any character except a control character (like vbLF) and validate what the user entered in the textbox's LostFocus event.
    • Use a TextBox instead of a MaskedTextBox and test each character the user enters in the TextChanged event.
    Please explain more.
    Saturday, September 13, 2014 5:21 PM
  • A "&" character in the mask will allow all the characters you want to allow plus some that you don't want to allow. If you set the mask to "&&&&" the user can enter four characters, but they may include characters you don't want to allow. You can handle the Validating event (which fires when the user attempts to leave the textbox) and use that to really make sure that all the characters are allowed. The event handler can also force the cursor to remain in the textbox (using e.Cancel = True) if you detect an error.

    Private Sub MaskedTextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MaskedTextBox1.Validating
        For Each textChar As Char In MaskedTextBox1.Text
            If Not Char.IsLetter(textChar) And textChar <> "/" And textChar <> "\" Then
                e.Cancel = True
                MessageBox.Show("Enter only letters or slashes")
                Exit Sub
            End If
        Next
    End Sub
    

    Of course if you are doing this, there isn't much point using a MaskedTextBox, and you might want to use just a regular TextBox.

    • Marked as answer by Arshia Aghaei Saturday, September 13, 2014 6:51 PM
    Saturday, September 13, 2014 6:15 PM