If you're triggering it from a button, then when the button is clicked set the global variable to TextBox.Text . You'll also probably want to set the textbox type to number. If you're going without the button, then have a different variable that stores the number. Then, have an event for when TextBox.Text != PreviousNumber and use it to set PreviousNumber = TextBox.Text .