|
-
Sep 22nd, 2000, 04:34 PM
#1
Thread Starter
Frenzied Member
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 ?
-
Sep 22nd, 2000, 04:38 PM
#2
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]
-
Sep 22nd, 2000, 04:47 PM
#3
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
-
Sep 23rd, 2000, 01:19 PM
#4
Thread Starter
Frenzied Member
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.
-
Sep 23rd, 2000, 01:35 PM
#5
What kind of a value is it?
-
Sep 24th, 2000, 05:19 AM
#6
Thread Starter
Frenzied Member
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
-
Sep 24th, 2000, 05:57 AM
#7
Frenzied Member
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.
-
Sep 24th, 2000, 07:14 AM
#8
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.
-
Sep 24th, 2000, 11:12 AM
#9
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|