|
-
May 23rd, 2000, 08:51 PM
#1
Thread Starter
New Member
Hi, I'm new to programming in VB so I hope you could help me with my problem.
In my first VB-project, I've made a timer with a interval=100 and then I've done some if-statements, like if the timer < 25 say this and so on, but it doesn't function, any ideas?
I haven't sat any start value, because it doesn't seem to work in VB 4.0.
-
May 23rd, 2000, 09:51 PM
#2
Frenzied Member
I think you are using the timer incorrectly.
assuming you mean a timer control, setting the interval to 100 just means the the timer event is triggered every 1/10 of a second.
Let me know waht it is you are tring to do and I'll see if I can help.
-
May 23rd, 2000, 10:26 PM
#3
Thread Starter
New Member
reply
I'm trying to do a program that is going to say something dependent on how long time the timer has gone.
If it has gone less than 25 then say that, in a messagebox and if it has gone between 25 and 50 say that in the msgbox, so the msgbox will be updated depending on how long time it has gone.
example:
Code:
if Timer1 < 10 then
MsgBox "blah blah"
end if
if Timer1 > 10 and Timer1 < 15 then
MsgBox "blah blah2"
end if
I sat the intervall to 100. It seems that I have to write Timer1.value, but that doesn't work, neither Timer1.min or timer1.max in the form_load either.
Any suggestions?
Thanks for your help.
-
May 23rd, 2000, 11:21 PM
#4
Addicted Member
In your timer event, you need to check the System time and compare that with the time at which the program was executed. The timer control can't really be used as an internal counter - all it does, as Mark Sreeves said, is trigger the code in your timer event every x milliseconds.
-
May 24th, 2000, 12:06 AM
#5
Addicted Member
heres an idea
set your timer intervals to 1000 (that is about equiv to one second).. in your general declarations declare a variable like so..
Code:
'In general declarations
Dim TimePassed As Long
'In timer event
TimePassed = TimePassed + 1
If TimePassed > 25 Then
'Do whatever
End If
Also keep in mind where you wish to set your TimePassed variables to 0, whether in the form load or whatever, depending on when the timer becomes active. Its early and I'm not awake, this all might not make sense :P Let me know if you have questions.
Thai
-
May 24th, 2000, 03:13 AM
#6
Thread Starter
New Member
Thai and all you others who has tried to help me; Thanks!
Thai, I'm quite new at this, so could you explain what you meant, I didn't understand really.
Thanks in advance!
-Osborn -q-
-
May 24th, 2000, 04:02 AM
#7
Addicted Member
The code I gave was a basic way to have the timer act when X amount of seconds have gone by, since I don't know exactly what you are trying to accomplish it is hard for me to help you further, reply and let me know what your objective is in this project or this function and I'll assist you in getting it done.
Thai
-
May 24th, 2000, 04:20 AM
#8
Thread Starter
New Member
My objective with this first program is that it would dispaly different types of messages depending on how long time that has passed.
Like when you install a progam you see what sort of files that are installed and how long time that has passed. I want something like that, but just that it will change message in a msgbox depending on how long time that has passed and I don't need to know how long time that has passed from the counting.
Can't you use something like timer1.value or start value or max value or something like that?
-
May 24th, 2000, 05:57 AM
#9
Addicted Member
No you must declare a variable to keep track of the time passed since the timer object does not have a min, max, or value property to it. Anyway, this is one way you could do it.
Code:
'In the general declarations
Private TimePassed As Long
'In the Form_Load event
Timer1.Interval = 1000
Timer1.Enabled = True
TimePassed = 0
'In the Timer1_Timer event
TimePassed = TimePassed + 1
Select Case TimePassed
Case Is = 30
MsgBox "30 seconds have passed."
Case Is = 60
MsgBox "60 seconds have passed."
End Select
Then you can add as many Cases as you wish, I think this is what you're looking for.
Thai
-
May 24th, 2000, 01:42 PM
#10
PowerPoster
more accurate
Hi Osborn, if you need a good accuracy result, then may be you should use the GetTickCount API function instead os using the timer to increase a variable.
Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim T1&, T2&
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
T1 = GetTickCount()
T2 = 0
End Sub
Private Sub Timer1_Timer()
T2 = GetTickCount()
Label1.Caption = (T2 - T1) / 1000 & " milisecond have passed..."
End Sub
-
May 24th, 2000, 09:35 PM
#11
Thread Starter
New Member
Thank you all for the help, the problem is now solved thanks to you!
Thai, I used what you said and it worked out fine.
Osborn -q
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
|