Results 1 to 11 of 11

Thread: Urgent Help needed...Comparing the output with previous values code in timer

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

    Unhappy 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:
    1. Private Sub tm_get_position_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tm_get_position.Tick
    2.         If flag_track = 1 Then
    3. Dim macs(), prob_proc() As String
    4.                 macs = New String() {"00112052E170", "0011218F1A60", "00112052ECC0", "00112052D840", "00112052F010", "00112052E5D0"}
    5.                 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"}
    6.                 Dim k, kk As Integer
    7.                 Dim max As Long
    8.                 Dim position As Integer
    9.                 Dim probablistic(49) As Long
    10.  
    11.  
    12.                 For kk = 0 To 49
    13.                     For k = 0 To 5
    14.                         sqlcomm3.Connection = sqlconn
    15.                         sqlcomm3.CommandType = CommandType.StoredProcedure
    16.  
    17.                         sqlcomm3.CommandText = prob_proc(kk)
    18.                         sqlcomm3.Parameters.Clear()
    19.                         q = New SqlParameter
    20.                         q.ParameterName = "@macs"
    21.                         q.Direction = ParameterDirection.Input
    22.                         q.SqlDbType = SqlDbType.NVarChar
    23.                         q.Value = macs(k)
    24.                         sqlcomm3.Parameters.Add(q)
    25.                         q = New SqlParameter
    26.                         q.ParameterName = "@gaussian"
    27.                         q.Direction = ParameterDirection.Output
    28.                         q.SqlDbType = SqlDbType.Int
    29.                         sqlcomm3.Parameters.Add(q)
    30.                         Try
    31.                             sqlcomm3.ExecuteNonQuery()
    32.                         Catch ex As Exception
    33.                             q.Value = 0
    34.                         End Try
    35.  
    36.                         Try
    37.                             If Convert.IsDBNull(q.Value) = True Then
    38.                                 q.Value = 25
    39.                             End If
    40.  
    41.                             If q.Value < 25 Then
    42.                                 q.Value = 25
    43.                             End If
    44.  
    45.                             If k = 0 Then
    46.                                 probablistic(kk) = q.Value
    47.                             Else
    48.                                 probablistic(kk) = probablistic(kk) * q.Value
    49.                             End If
    50.                        Catch ex As Exception
    51.                             If k = 0 Then
    52.                                 probablistic(kk) = 25
    53.                             Else
    54.                                 probablistic(kk) = probablistic(kk) * 25
    55.                             End If
    56.                         End Try
    57.                     Next
    58.                 Next
    59.                 max = probablistic(0)
    60.                 For kk = 0 To 49
    61.                     If max < probablistic(kk) Then
    62.                         max = probablistic(kk)
    63.                         position = kk
    64.                     End If
    65.                 Next
    66.  
    67.                 Me.Controls.Remove(pbox)
    68.                 SuspendLayout()
    69.                 pbox.Image = System.Drawing.Image.FromFile(("C:\XandY\Image\dot1.jpg"))
    70.                 pbox.Top = pointx(position + 1).Y
    71.                 pbox.Left = pointx(position + 1).X
    72.                 pbox.Width = 10
    73.                 pbox.Height = 10
    74.                 Me.Controls.Add(pbox)
    75.                 pbox.BringToFront()
    76.                 ResumeLayout()
    77.            
    78.     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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private previousValue As Integer
    2.  
    3. Private Sub Timer1_Tick(ByVal sender As Object, _
    4.                         ByVal e As EventArgs) Handles Timer1.Tick
    5.     Dim currentValue As Integer
    6.  
    7.     'Calculate currentValue here.
    8.  
    9.     Select Case currentValue
    10.         Case Is < Me.previousValue
    11.  
    12.         Case Me.previousValue
    13.  
    14.         Case Is > Me.previousValue
    15.  
    16.     End Select
    17.  
    18.     Me.previousValue = currentValue
    19. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

    Red face Re: Urgent Help needed...Comparing the output with previous values code in timer

    Thank u so much for reply....i will xplain u clearly wot i want...the code i given makes the output as 'position=35' for 1st tick

    'position=22' for 2nd tick after 580milli seconds
    'position= 45' for 3rd tick
    'position= 33' for 4th tick......similarly.....it goes like this ..its just an xample..

    now wot i want is i want to compare the 3rd value with 2nd value and test the condition i.e; 45-22=23

    now test condition if difference>10 then run some code....else run the same code....

    similarly i want to compare 4th with 3rd....33-45=12...like wise all...this is my problem...could you please help me out...send me the code clearly ..i am very new to VB.... ...thank u so much for ur reply dude....

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

    Red face Re: Urgent Help needed...Comparing the output with previous values code in timer

    cool thank u so much dude...so we need to include another timer now..... and compare the values in it....cool...can u help with the timing of this timer...i.e; wen to start this timer to get the current value and all...it wil be gr8 for ur help..

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

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

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    18

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

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width