Vb6 Timer control

Events to be tracked with a timer

Page 1 of 1

5 Replies - 4761 Views - Last Post: 06 July 2009 - 02:27 AM Rate Topic: -----

#1 Singende  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-March 09

Vb6 Timer control

Posted 03 July 2009 - 03:08 AM

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***

  
'[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
   


Is This A Good Question/Topic? 0
  • +

Replies To: Vb6 Timer control

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Vb6 Timer control

Posted 03 July 2009 - 05:57 AM

Just a pointer :code:
Was This Post Helpful? 0
  • +
  • -

#3 Singende  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-March 09

Re: Vb6 Timer control

Posted 03 July 2009 - 06:52 AM

just a pointer what do you mean firebolt?


'[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


Was This Post Helpful? 0
  • +
  • -

#4 birdflu9999  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 26
  • Joined: 26-June 09

Re: Vb6 Timer control

Posted 03 July 2009 - 08:34 AM

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: 03 July 2009 - 08:36 AM

Was This Post Helpful? 0
  • +
  • -

#5 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: Vb6 Timer control

Posted 03 July 2009 - 08:58 PM

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...
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
Was This Post Helpful? 1
  • +
  • -

#6 Singende  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-March 09

Re: Vb6 Timer control

Posted 06 July 2009 - 02:27 AM

thanks i am now working towards those lines. Am sure it will work out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1