I was playing around with comparing
Private Declare Function GetTickCount Lib "kernel32" () As Long
to the Timer in VB.
The CPU usage for the API call was about 50% and the CPU usage for the VB Timer was basically nothing. The code I was using is below. I don't know why but I always assumed API calls were more efficient. Did I do something wrong? All of my VB6 knowledge has been self taught. The only formal program classes I have had were in Fortran and GW Basic - many - many moons ago.
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim t1 As Long
Dim t2 As Long
Dim Countit As Long
''Make Sure timer is OFF
Timer1.Enabled = False
'Hide visual indicators
Shape1.Visible = False
Shape2.Visible = False
''If no value or negative value in text1 get out
If Val(Text1.Text) < 1 Then
Shape1.Visible = True
Shape2.Visible = True
MsgBox "Booboo"
Exit Sub
End If
''Get milliseconds to count
Countit = Val(Text1.Text)
''Set Timer
Timer1.Interval = Countit
'set Tickcount
t1 = GetTickCount
''Start Timers
If chkTimer.Value = 1 Then Timer1.Enabled = True
If chkTicker.Value = 0 Then Exit Sub
Do
''Keep keyboard, mouse and screen from freezing
DoEvents
t2 = GetTickCount
Loop Until t2 - t1 = Countit
Shape1.Visible = True
End Sub
Private Sub Form_Load()
End Sub
Private Sub Text1_DblClick()
''Clear Textbox
Text1.Text = ""
End Sub
Private Sub Timer1_Timer()
Shape2.Visible = True
Timer1.Enabled = False
End Sub
Private Declare Function GetTickCount Lib "kernel32" () As Long
to the Timer in VB.
The CPU usage for the API call was about 50% and the CPU usage for the VB Timer was basically nothing. The code I was using is below. I don't know why but I always assumed API calls were more efficient. Did I do something wrong? All of my VB6 knowledge has been self taught. The only formal program classes I have had were in Fortran and GW Basic - many - many moons ago.
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim t1 As Long
Dim t2 As Long
Dim Countit As Long
''Make Sure timer is OFF
Timer1.Enabled = False
'Hide visual indicators
Shape1.Visible = False
Shape2.Visible = False
''If no value or negative value in text1 get out
If Val(Text1.Text) < 1 Then
Shape1.Visible = True
Shape2.Visible = True
MsgBox "Booboo"
Exit Sub
End If
''Get milliseconds to count
Countit = Val(Text1.Text)
''Set Timer
Timer1.Interval = Countit
'set Tickcount
t1 = GetTickCount
''Start Timers
If chkTimer.Value = 1 Then Timer1.Enabled = True
If chkTicker.Value = 0 Then Exit Sub
Do
''Keep keyboard, mouse and screen from freezing
DoEvents
t2 = GetTickCount
Loop Until t2 - t1 = Countit
Shape1.Visible = True
End Sub
Private Sub Form_Load()
End Sub
Private Sub Text1_DblClick()
''Clear Textbox
Text1.Text = ""
End Sub
Private Sub Timer1_Timer()
Shape2.Visible = True
Timer1.Enabled = False
End Sub