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 ?
Printable View
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 ?
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]
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
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.
What kind of a value is it?
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
you can, just do
but it will consume system memoryCode:private stopme As Boolean
' in form_load
stopme = false
do while stopme = false
toolbarcheck()
doEvents
loop
'in form_unload
stopme = true
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:
Summary: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
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.
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 ;)