|
-
Oct 31st, 2008, 01:57 AM
#1
Thread Starter
New Member
Unable to decrement numeric LED in my ActiveX Control
Hi all,
I am using VB 6.0, and want to use a Timer in order to decrement GMS NumLED from 3:00 to 0:00, I have tried, but program crashes after first run.
So, I made a simple application in which I only included the NumLED, Timer, and a Start label. There are no errors, code compiles and runs fine, I have tried to debug it too, all program flow is as expected, but it doesn't decrement the NumLED. I would be very thankful for any suggestions, links or fix, or even a hint about, what could have gone wrong?
I am attaching complete code here for reference:
Code:
' simple program to decrement NUM LED timer using timer component
Option Explicit
' Label start click event
Private Sub lblStart_Click()
Timer1.Enabled = True
End Sub
' Timer tick event
Private Sub Timer1_Timer()
Static timeValue As Integer
timeValue = 10
Do While (timeValue <> 0)
timeValue = DecrementNumLedTime(timeValue)
NumLED1.Value = timeValue
Loop
Timer1.Enabled = False
End Sub
' Decrementing NumLED timer
Public Function DecrementNumLedTime(ByVal timeValue As Integer) As Integer
Static quotient As Integer
Static remainder As Integer
remainder = timeValue Mod 60
quotient = timeValue / 60
DecrementNumLedTime = remainder - 1
End Function
-
Oct 31st, 2008, 09:41 AM
#2
Re: Unable to decrement numeric LED in my ActiveX Control
Welcome to VBForums 
Your DecrementNumLedTime seems to be more complex than needed, and not accurate either (eg: it ignores quotient). It seems to me that the only code required in it is this: DecrementNumLedTime = timeValue - 1 If that works, using a function is overkill, as you could simply do it inline instead.
I also don't see the point of using a Timer as you have, as all it is doing is delaying the start of the process - what I suspect you wanted is to have a delay between the numbers, in which case you should remove the loop and re-organise the code a little.
Here is what I think you wanted:
Code:
' simple program to decrement NUM LED timer using timer component
Option Explicit
Private timeValue As Integer
' Label start click event
Private Sub lblStart_Click()
Timer1.Enabled = True
timeValue = 10
End Sub
' Timer tick event
Private Sub Timer1_Timer()
If timeValue <= 0 Then
Timer1.Enabled = False
Exit Sub
End If
timeValue = timeValue - 1
NumLED1.Value = timeValue
End Sub
-
Nov 1st, 2008, 12:59 AM
#3
Thread Starter
New Member
Re: Unable to decrement numeric LED in my ActiveX Control
Hello,
Thanks a lot.
It works now.
One more thing though.
I want to use alphanumeric value in NumLED as 3:00 it is supposed to decrease like 2:59, 2:58 and so on...That's why I used the quotient and remainder.
How do I achieve that?
Thanks.
-
Nov 1st, 2008, 07:43 AM
#4
Re: Unable to decrement numeric LED in my ActiveX Control
I have no idea what kind of things NumLED allows, but assuming it does allow that kind of value, you can use something like this to show timeValue as you want:
Code:
NumLED1.Value = (timeValue \ 60) & ":" & Format(timeValue Mod 60, "00")
Note that \ is integer division - the result will have no decimal places (so while 2/5 = 2.5, 2\5 = 2).
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
|