Hi,

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!

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
   Else
      Return False
   End If
End Sub

Thanks very much, this has helped me no end!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.