I've solved my problem but don't understand why my first attempt didn't work. I'd be grateful for future reference if any one can tell me.
The problem was trying to find the lowest non-zero value in a column of a list which holds date/time stamped CSV data.
I initially couldn't get it to ignore any zeros.
The following didn't work (if a zero was present, it was assigned to dblMin)
I adjusted the If section to;
But I still got zeros being assigned to dblMin.
I got it to work as I want using;
This successfully returns the lowest non-zero figure but I don't really see the difference between it and my first efforts.
Am I misunderstanding how <> works, or am I missing something else?
Many thanks in advance.
The problem was trying to find the lowest non-zero value in a column of a list which holds date/time stamped CSV data.
I initially couldn't get it to ignore any zeros.
The following didn't work (if a zero was present, it was assigned to dblMin)
B4X:
'find min figure in specified column in lstFullPeriodData
Public Sub ColumnMin(columnNum As Int) As Double
Private fullDataRow As String
Private lstFullDataRowSplit As List
Private dblMin = 999999 As Double
lstFullDataRowSplit.Initialize
For i = 0 To lstFullPeriodData.Size-1
fullDataRow=lstFullPeriodData.Get(i)
lstFullDataRowSplit=Regex.Split(",", fullDataRow)
If lstFullDataRowSplit.Get(columnNum) <> 0 And lstFullDataRowSplit.Get(columnNum) < dblMin Then dblMin = lstFullDataRowSplit.Get(columnNum)
Next
Return dblMin
End Sub
I adjusted the If section to;
B4X:
If lstFullDataRowSplit.Get(columnNum) <> 0 Then
If lstFullDataRowSplit.Get(columnNum) < dblMin Then
dblMin = lstFullDataRowSplit.Get(columnNum)
Else
dblMin = dblMin
End If
End If
I got it to work as I want using;
B4X:
If lstFullDataRowSplit.Get(columnNum) < 0 Or lstFullDataRowSplit.Get(columnNum) > 0 Then
If lstFullDataRowSplit.Get(columnNum) < dblMin Then
dblMin = lstFullDataRowSplit.Get(columnNum)
Else
dblMin = dblMin
End If
End If
Am I misunderstanding how <> works, or am I missing something else?
Many thanks in advance.