Results 1 to 4 of 4

Thread: Can a timers 'interval' be Set via a Textbox value edited on a windows form?

  1. #1

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Question Can a timers 'interval' be Set via a Textbox value edited on a windows form?

    I have a timer set at 250000 after I click "start" on my program (i.e. it doesn't start till i tell it to). My question is...if I place Textbox22.Text on my form...Can edit the timer pause in the program on the fly (*aka already compiled*) via that Textbox22.Text & If so how do I do it. Can I just place Textbox22.Text in place of seconds on the actual timer edit window in my visual studio GUI? And just have Textbox22's text already set to 250000? (then later i can change it before starting the program/timer to achieve a different delay before the timer pops off) If not how would I go about making a timer's amount of time editable via the compiled windows form?

    I originally did a google search & came up with this msdn forum post http://social.msdn.microsoft.com/For...5-139b0b597546
    So i did my homework before posting...its just that post is way over my head & complicated for me. I think that person's needs were not as simple as mine.

    Any example is appreciated! And I always make sure to give thanks for all replies * well the ones not making fun of me anyways *

    Thanks Bunches! GoOse
    Last edited by jalexander; Nov 28th, 2012 at 01:06 AM. Reason: updated thread title to be more descriptive & fixed my dyslexic spelling errors
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?

    Think about it. If you want to display some text in a TextBox or Label at run time, what do you do? You simply write some code to set the Text property, right? The Interval property of a Timer is just a property, the same a the Text of a TextBox or Label, so you set it the same way.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?

    So then using button1_click.... Timer1.Interval = TextBox1.Text
    The same way I would do button2_click .... TextBox1.Text = "yo momma"
    I'm guessing? Difference is...I was thinking that the static interval set via the IDE would be somehow different. Thanks for making me feel dumb, you got the perfect recipe for that... for me lol
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Can a timers 'interval' be Set via a Textbox value edited on a windows form?

    Here is one way of doing this. Note that I check that what is in the textbox is numeric.

    Code:
        Private Sub TextBox1_TextChanged(sender As System.Object, _
                                         e As System.EventArgs) Handles TextBox1.TextChanged
            'used to set timer interval on the fly
            'user input is number of ms followed immediately by #
            'e.g. 1000# = 1000 ms
            If TextBox1.Text.Trim.EndsWith("#") Then 'does textbox end with #
                'yes
                Dim s As String = TextBox1.Text.Trim.TrimEnd(New Char() {"#"c}) 'get number part
                Dim i As Integer
                If Integer.TryParse(s, i) Then 'if it is an integer set timer1.interval
                    Timer1.Interval = i
                    TextBox1.Text = ""
                Else
                    Debug.WriteLine("error nan") 'not a number
                End If
            End If
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width