|
-
Jan 4th, 2009, 07:26 PM
#1
Thread Starter
Junior Member
Urgent Help needed...Comparing the output with previous values code in timer
Hi everyone,
I am new to VB programming. I am doing a project on comparing the output value of a code running on timer for every 580mseconds. the objective of this project is to compare the output value of the code to the next output value of same code which is running in timer for every 580ms. i will explain you clearly...here is my code....
vb Code:
Private Sub tm_get_position_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tm_get_position.Tick
If flag_track = 1 Then
Dim macs(), prob_proc() As String
macs = New String() {"00112052E170", "0011218F1A60", "00112052ECC0", "00112052D840", "00112052F010", "00112052E5D0"}
prob_proc = New String() {"probs1", "probs2", "probs3", "probs4", "probs5", "probs6", "probs7", "probs8", "probs9", "probs10", "probs11", "probs12", "probs13", "probs14", "probs15", "probs16", "probs17", "probs18", "probs19", "probs20", "probs21", "probs22", "probs23", "probs24", "probs25", "probs26", "probs27", "probs28", "probs29", "probs30", "probs31", "probs32", "probs33", "probs34", "probs35", "probs36", "probs37", "probs38", "probs39", "probs40", "probs41", "probs42", "probs43", "probs44", "probs45", "probs46", "probs47", "probs48", "probs49", "probs50"}
Dim k, kk As Integer
Dim max As Long
Dim position As Integer
Dim probablistic(49) As Long
For kk = 0 To 49
For k = 0 To 5
sqlcomm3.Connection = sqlconn
sqlcomm3.CommandType = CommandType.StoredProcedure
sqlcomm3.CommandText = prob_proc(kk)
sqlcomm3.Parameters.Clear()
q = New SqlParameter
q.ParameterName = "@macs"
q.Direction = ParameterDirection.Input
q.SqlDbType = SqlDbType.NVarChar
q.Value = macs(k)
sqlcomm3.Parameters.Add(q)
q = New SqlParameter
q.ParameterName = "@gaussian"
q.Direction = ParameterDirection.Output
q.SqlDbType = SqlDbType.Int
sqlcomm3.Parameters.Add(q)
Try
sqlcomm3.ExecuteNonQuery()
Catch ex As Exception
q.Value = 0
End Try
Try
If Convert.IsDBNull(q.Value) = True Then
q.Value = 25
End If
If q.Value < 25 Then
q.Value = 25
End If
If k = 0 Then
probablistic(kk) = q.Value
Else
probablistic(kk) = probablistic(kk) * q.Value
End If
Catch ex As Exception
If k = 0 Then
probablistic(kk) = 25
Else
probablistic(kk) = probablistic(kk) * 25
End If
End Try
Next
Next
max = probablistic(0)
For kk = 0 To 49
If max < probablistic(kk) Then
max = probablistic(kk)
position = kk
End If
Next
Me.Controls.Remove(pbox)
SuspendLayout()
pbox.Image = System.Drawing.Image.FromFile(("C:\XandY\Image\dot1.jpg"))
pbox.Top = pointx(position + 1).Y
pbox.Left = pointx(position + 1).X
pbox.Width = 10
pbox.Height = 10
Me.Controls.Add(pbox)
pbox.BringToFront()
ResumeLayout()
End Sub
Here we get an output value for the variable 'position' . the output will be (0-49).this code is running on timer. this code runs for every 580milliseconds. each and every time it gives the output value for variable 'position'. i need to compare the value of this variable for the next output value after 580milliseconds. can you please help me on this issue.i am not getting any idea how to compare this values. after storing the value i need to check for condition and get the result...can u please respond as soon as possible...
Last edited by RobDog888; Jan 4th, 2009 at 07:55 PM.
-
Jan 4th, 2009, 07:54 PM
#2
Re: Urgent Help needed...Comparing the output with previous values code in timer
Thread Moved
Welcome to the Forums.
I added [highlight=vb] code tags to make your code more readable
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 4th, 2009, 08:00 PM
#3
Re: Urgent Help needed...Comparing the output with previous values code in timer
I don't see how you can compare the current value with the next value because you won't have the next value until the next Tick event. I assume you mean you want to compare with the previous value. Unless I'm missing something it should just be something like this:
vb.net Code:
Private previousValue As Integer Private Sub Timer1_Tick(ByVal sender As Object, _ ByVal e As EventArgs) Handles Timer1.Tick Dim currentValue As Integer 'Calculate currentValue here. Select Case currentValue Case Is < Me.previousValue Case Me.previousValue Case Is > Me.previousValue End Select Me.previousValue = currentValue End Sub
-
Jan 4th, 2009, 11:08 PM
#4
Thread Starter
Junior Member
-
Jan 4th, 2009, 11:23 PM
#5
Re: Urgent Help needed...Comparing the output with previous values code in timer
I've basically already shown you. You store the previous value in a member variable. On each Tick you get the current value and then you use both the current value and the previous value however you see fit. Finally you replace the previous value with the current value, ready for the next Tick.
-
Jan 4th, 2009, 11:33 PM
#6
Thread Starter
Junior Member
-
Jan 4th, 2009, 11:38 PM
#7
Re: Urgent Help needed...Comparing the output with previous values code in timer
I'm afraid I don't really understand what you're asking for.
-
Jan 4th, 2009, 11:45 PM
#8
Thread Starter
Junior Member
Re: Urgent Help needed...Comparing the output with previous values code in timer
ooops..as u said in ur code...i had a doubt that do we need to include another timer??
-
Jan 5th, 2009, 12:05 AM
#9
Re: Urgent Help needed...Comparing the output with previous values code in timer
You already have a Timer don't you? You don't need another one, unless you actually need another one.
-
Jan 5th, 2009, 12:42 AM
#10
Thread Starter
Junior Member
Re: Urgent Help needed...Comparing the output with previous values code in timer
yes.. i am already having one timer..can i run ur code in the same timer?..i dont think so bcoz....if we run in the same timer how can we store the current value and compare??
-
Jan 5th, 2009, 12:59 AM
#11
Re: Urgent Help needed...Comparing the output with previous values code in timer
One of us is missing the point here. You would only need two Timers if you have two operations you need executed at different intervals. Do you? If so then you need two Timers. If not then what would the second Timer be for?
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
|