I'm developing a data logging application using VB for the actual logging to a MySQL database. I'm reading a value from a device and then running an insert query every minute. This is great but if the value doesnt change all day then my records are going to all be the same. I'd like to try and calculate the percentage of change on the value and only run the insert query if the percentage of change is greater than, say 5%.

Does this sound possible and would anyone mind in posting some sample code?

Thanks alot!

8 Years
Discussion Span
Last Post by benhowdle89

Here's a code snippet for calculating an increase in percent.
For example, an increase from 2 to 10 equals 400%.

Private Function PercentIncrease() As Boolean
   Dim value1 As Double   'Value from database
   Dim value2 As Double   'Value from device
   Dim calc As Double
   calc = ((value2 - value1) / value1 * 100)

   If calc > 5 Then
      Return True
      Return False
   End If
End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.