Results 1 to 9 of 9

Thread: Do Whille App Running

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    In my app i want it right from the milisecond it starts running to the millisecond it stops i want it to do something. How can this be acheived ?

  2. #2
    Guest
    Put a Timer on the main form in your app, set its Enabled property to True and its Interval property to 1.
    Put whatever you want to do in the Timer event of the Timer.

    It will start running when the form will load, and it will halt when the form is unloaded.

    If you don't need the interval between the actions to be exactly 1 milisecond, it's recommended that you put a DoEvents in the Timer event.

    BTW, what kind of an action is it?

    [Edited by Sc0rp on 09-22-2000 at 05:41 PM]

  3. #3
    Guest
    The Timer control shipped with VB is not accurate. As a work around, use GetTickCount.
    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Dim bTime As Boolean
    
    Sub TimerEx(Interval As Long)
        Do While bTime = True
            Start = GetTickCount
            
            Do While GetTickCount < Start + Interval
            DoEvents
            Loop
            
            '<-- Place your code here -->
            
        Loop
    End Sub
    
    Private Sub Command1_Click()
        'Start our Timer at an interval to 1ms
        bTime = True
        TimerEx (1)
    End Sub

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Thanks i want my app to allways be testing if a value > 0 but my app crashes because the timer on vb is not going all the time thers a gap during the timer interval of 1 that can cause a crash.

  5. #5
    Guest
    What kind of a value is it?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Integer, I want it to do this while my app is running,

    If MyValue > 0 then
    ToolbarsCheck
    End if

    P:s Isn't there something like this i can do:

    Do

    While IsRunning(App)

    or app.running

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    you can, just do
    Code:
    private stopme As Boolean
    ' in form_load
    stopme = false
    do while stopme = false
    toolbarcheck()
    doEvents
    loop
    
    'in form_unload
    stopme = true
    but it will consume system memory
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8
    Guest
    I thought about this problem yesterday, and I got an idea.
    It's not the perfect idea but it's worth trying.
    Let's say, for example, that your variable name is intMyVar. You want to make sure it's always positive, right?
    Put a TextBox on your form and set it's Visible property to False. Name it txt_intMyVar.
    Now, instead of setting, for example: intMyVar = 49, do this: txt_intMyVar = 49.
    In order to check if the value is positive, put this code in the Change event of the TextBox:
    Code:
    Private Sub txt_intMyVar_Change()
        If Val(txt_intMyVar) < 0 Then
            'Enter code to do if the value is negative...
        End If
    End Sub
    Summary:
    Instead of a variable we are using a TextBox because a TextBox fires an event when its contents change.

    I hope it helps.
    Of course this solution is impractical if you have a lot of variables you need to track.

    NOTE: I think for this case you can even use a Label instead of a TextBox. It also has a Change event.

  9. #9
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Let me see, how's the variable set? I assume by program, but hey, why don't check it when setting it huh? just like

    var = rnd
    If var > 0 Then Call Toolbarcheck()

    and if it's set by a human, you don't have to check it, just use the Change_event.

    Anyway, smart thinking Scorp, it'll work
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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