VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,441 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,486 people online right now. Registration is fast and FREE... Join Now!




Vb6 Timer control

 

Vb6 Timer control, Events to be tracked with a timer

Singende

3 Jul, 2009 - 02:08 AM
Post #1

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 5

Hi Programmers

i am writing some simulator programme and at some point some event is triggered for example, a sensor fails, So when a sensor fails i want to start a timer for this sensor which inreement until time T to offset the fail state.
i have 72 sensors and i can have more sensors failing so i can not assign a timer control for each if so i think i will have to put 72 timers.

in short -i have 72 sensors
-an randomly selected sensor can fail
- when it fails i give it a random time to come off the fail state (offset)
-timer for this bay to start counting towards offset time
- sensor to come off the fail state when counter reaches the offset time.
-****my problem is i have more than a bay which can fail so how can i have each bay that fails get tracked by a timer***

CODE
  
'[AS] 6/4/2009 occassionaly a sensor fails
Private Sub tmrRandomSensorFailure_Timer()
     Dim intbay As Integer
     Dim intIdletime As Integer
    
     mintFailTimer = mintFailTimer + 1
    
    If mintFailTimer = mintNextFailTime Then
       mintMyValue = Int((100 * Rnd) + 1) 'get a random number between 1 and 100
          ' If mintMyValue <= mintFailRate Then ' if the randomly selected number falls under failrate then cause a sensor failure
            mintMyValue = Int((72 * Rnd) + 1) ' pick a bay between 0 and 72 at random
            
            cboBayStatus(mintMyValue - 1).ListIndex = 0 ' set this combo to sensor failure
                
            intbay = mintMyValue  ' this is the bay  set to fail state
            
            intIdletime = mintFailTime + (Int(-mintOffsetTime * Rnd) + mintOffsetTime) ' time for which the bay is goin to remain in fail state
            
            marrBayTrack(intbay) = intIdletime ' save the idle time in an array position which matches its bay
            
            marrCounter(intbay) = marrCounter(intbay) + 1 '*******
                
                
                Call cmdSetState_Click ' Set the bay to sensor failure
                mintNextFailTime = Int((mintSFMax - mintSFmin + 1) * Rnd) + mintSFmin ' determine the next random time a sensor is gonna fail
         ' End If
           mintFailTimer = 0 ' reset the timer and wait for the next fail time
    End If
    
End Sub
  


User is offlineProfile CardPM
+Quote Post


firebolt

RE: Vb6 Timer Control

3 Jul, 2009 - 04:57 AM
Post #2

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,463



Thanked: 75 times
Dream Kudos: 1675
My Contributions
Just a pointer code.gif
User is offlineProfile CardPM
+Quote Post

Singende

RE: Vb6 Timer Control

3 Jul, 2009 - 05:52 AM
Post #3

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 5

just a pointer what do you mean firebolt?


CODE
'[AS] 6/4/2009 occassionaly a sensor fails
Private Sub tmrRandomSensorFailure_Timer()
Dim intbay As Integer
Dim intIdletime As Integer

mintFailTimer = mintFailTimer + 1

If mintFailTimer = mintNextFailTime Then
mintMyValue = Int((100 * Rnd) + 1) 'get a random number between 1 and 100
' If mintMyValue <= mintFailRate Then ' if the randomly selected number falls under failrate then cause a sensor failure
mintMyValue = Int((72 * Rnd) + 1) ' pick a bay between 0 and 72 at random

cboBayStatus(mintMyValue - 1).ListIndex = 0 ' set this combo to sensor failure

intbay = mintMyValue ' this is the bay set to fail state

intIdletime = mintFailTime + (Int(-mintOffsetTime * Rnd) + mintOffsetTime) ' time for which the bay is goin to remain in fail state

marrBayTrack(intbay) = intIdletime ' save the idle time in an array position which matches its bay

marrCounter(intbay) = marrCounter(intbay) + 1 '*******


Call cmdSetState_Click ' Set the bay to sensor failure
mintNextFailTime = Int((mintSFMax - mintSFmin + 1) * Rnd) + mintSFmin ' determine the next random time a sensor is gonna fail
' End If
mintFailTimer = 0 ' reset the timer and wait for the next fail time
End If

End Sub

User is offlineProfile CardPM
+Quote Post

birdflu9999

RE: Vb6 Timer Control

3 Jul, 2009 - 07:34 AM
Post #4

New D.I.C Head
Group Icon

Joined: 26 Jun, 2009
Posts: 22



Thanked: 2 times
Dream Kudos: 25
My Contributions
the pointer firebolt was talking about was that you must paste your code between the tags
[C0DE] ..... [/C0DE]

This post has been edited by birdflu9999: 3 Jul, 2009 - 07:36 AM
User is offlineProfile CardPM
+Quote Post

vb5prgrmr

RE: Vb6 Timer Control

3 Jul, 2009 - 07:58 PM
Post #5

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 459



Thanked: 30 times
My Contributions
You have a couple of options here...

One is to use a single timer with an assortment of array's that corresponds to your sensors and a timeout count.

The other is to place a single timer control on your form and set its index to zero (0). Then you can load other timers as needed and refer to them by index just like you would load any other control at runtime...
CODE

Load Timer1(NewIndex)

Once again with array's but easier because you can use the index of the timer instead of using a loop to test and increment.


Good Luck


User is offlineProfile CardPM
+Quote Post

Singende

RE: Vb6 Timer Control

6 Jul, 2009 - 01:27 AM
Post #6

New D.I.C Head
*

Joined: 9 Mar, 2009
Posts: 5

thanks i am now working towards those lines. Am sure it will work out.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:17AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month