CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    12

    Post Monitoring a Variable [VB.net 2008]

    Hi

    I am trying to make a program the will monitor if the certain variable changes.

    lets say if the default value is 0, the program will just listen, but when the value changes to 1. something will happen.

    here is what i have thought
    Code:
    Do Until Exit_button is clicked
    
    If val != 0 Then
       Execute Statement
    End if
    
    Loop
    how can i do this? in VB.net if its just that, the program wont let me do anything. since it is busy with the endless loop.

    thanks

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Monitoring a Variable [VB.net 2008]

    The UI is handled by a seperate thread, so you have to either have
    Code:
    application.doevents
    inside your loop or place your loop code in a background worker thread.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  3. #3
    Join Date
    Dec 2008
    Posts
    12

    Re: Monitoring a Variable [VB.net 2008]

    Thanks, i tried done the background component, now i need to produce a status report while the event is being handled like. let say every 1 second. in a texbox it will say the word "Listening" to it and it will refresh oh let say 2 seconds.

    since i can't just change the property of a textbox in the DoWork event of the BGW component, and the RunWorkerComplete event will only be initiated as soon as the task is done, or i purposely cancel the task. how do i go around this?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Monitoring a Variable [VB.net 2008]

    BGW has a FLAG that is used as a DELEGATE, which can be used to initiate code in both threads.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Dec 2008
    Posts
    12

    Re: Monitoring a Variable [VB.net 2008]

    is there a sample code so that i can have a idea on how to do that?

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Monitoring a Variable [VB.net 2008]

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured