B4R Question Double, division error

Mostez

Active Member
Hello,
I've these string variables and I want to get number of units (count objects on weighing scale) when i divide weight by unit-weight arduino MEGA crashes with no restart even if I changed type of
NumberOfUnits variable from Ulong to Double. If weight = 0 no errors occured. any Ideas?

I read UnitWeight from SD card one time and store it in global variable
B4X:
Dim strUnitWeight As String = "0.004"
weight read from loadcell every 1000 ms, calculation and data display on lcd done inside timer_tick sub

B4X:
Private Sub wTimer_tick()
Dim strWeight As String = GetWeight() 'i.e "400" grams
Dim dUnitWeight As Double = strUnitWeight
Dim dWeight As Double = strWeight
Dim NumberOfUnits as Ulong= dWeight / dUnitWeight
 

Mostez

Active Member
B4X:
private Sub GetWeight() As String
Dim Times As Int = 4
    Dim Units As Long = HX711.GetUnits(Times)
    Dim Tmps As String
    Select UnitofMeasure 'global var
        Case SYS_UNIT_GRAMS 'global const
            Tmps = NumberFormat(Units,1,0)
        Case SYS_UNIT_KG
            Tmps = NumberFormat(Units /1000,1,3)
        Case SYS_UNIT_OZ
            Tmps = NumberFormat(Units * 0.0352739619,1,3)
        Case SYS_UNIT_POUND
            Tmps = NumberFormat(Units * 0.0352739619 * 0.0625,1,3)
    End Select
    Return Tmps
End Sub
 
Top