Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

Timers and Select Case Statements

$
0
0
Hello all.

I have written some pretty hefty programs in VB6 quite a while ago.... but now have stumbled upon an issue when looking into them further...

I have one timer running the backbone of the program, It has an interval of 100 and within this timer I have a select case statement.

Basically for each 10th of a second the timer should call a routine, I have stripped it down for it to be easily viewed. But basically the code below isn't working.

My program receives a flow rate and then calculates the total, so lets say that the flow rate per minute is 100. After one minute of totaling you'd expect the total to be 100.... but it isn't. Why though?

See the code below:


Public i As Integer
Public Total As Double
Public Flow As Double
Public PerSec As Double

Private Sub cmdStart_Click()
Timer1.Enabled = True
End Sub

Private Sub cmdStop_Click()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()

'£ Increment Counter
i = i + 1

Select Case i
'£ Timer interval set to 100, the below
'£ code will run once per second.

Case 10
Flow = Val(txtFlowRate.Text) '£ This value is 265
PerSec = Flow / 60

Total = Total + PerSec
txtTotal.Text = Total

'£ Reset Counter
i = 0
End Select

End Sub

Viewing all articles
Browse latest Browse all 21096

Trending Articles