B4J Question Why doesn't this 'Select' work?

GarryP64

Member
The log command prints out a value for HLTt_f(0) so it should be a legit value to compare to. The error say's I am missing a parameter, but I have no idea what it is.

B4X:
Sub AStream_NewData (Buffer() As Byte)
    Dim s As String = BytesToString(Buffer, 0 ,Buffer.Length, "utf8")
    txtLogs.Text = txtLogs.Text & BytesToString(Buffer, 0, Buffer.Length, "utf8")
    If s.StartsWith("HLT") = True Then
        Dim hlt_s As String = BytesToString(Buffer, 3, Buffer.Length - 3, "utf8")
        lblHLTtemp.Text = hlt_s
        Dim HLTh_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(txtHLThigh.PromptText, "utf8"))
        Dim HLTl_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(txtHLTlow.PromptText, "utf8"))
        Dim HLTt_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(hlt_s, "utf8"))
        Log(HLTt_f(0))
        Log(HLTh_f(0))
        Log(HLTl_f(0))
        Select HLTt_f(0)
            Case > HLTh_f
                lblHLTtemp.TextColor = fx.Colors.Red
            Case < HLTl_f
                lblHLTtemp.TextColor = fx.Colors.Blue
            Case Else
                lblHLTtemp.TextColor = fx.Colors.Black
        End Select
    End If
End Sub
 

Sandman

Expert
Licensed User
Longtime User
It would have been helpful if you had shared the actual error message. Please update your post with it, and also include it in future threads.

As for your issue, I don't think it's possible to do that kind of comparison with a select. Switch to an if instead, and I imagine it will work fine.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Your case Statement Case > HLTh_f is not a valid format. The comparison needs to be complete.

You could use something like:

B4X:
Select True
        Case HLTt_f(0) > HLTh_f
            lblHLTtemp.TextColor = fx.Colors.Red
        Case HLTt_f(0) < HLTl_f
            lblHLTtemp.TextColor = fx.Colors.Blue
        Case Else
            lblHLTtemp.TextColor = fx.Colors.Black
    End Select
:
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
HLTh_f is also an array so it probably should have an index too. HLTh_f(0)
 
Upvote 0

emexes

Expert
Licensed User
On a related note - and admittedly flying blind without seeing hlt_s -

I would be surprised if these lines are doing what you intend them to do:

B4X:
        Dim HLTh_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(txtHLThigh.PromptText, "utf8"))
        Dim HLTl_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(txtHLTlow.PromptText, "utf8"))
        Dim HLTt_f() As Float = bc.FloatsFromBytes(bc.StringToBytes(hlt_s, "utf8"))
        Log(HLTt_f(0))
        Log(HLTh_f(0))
        Log(HLTl_f(0))

but I'll wait for a new question thread before guessing suggestions of what might work. šŸ»
 
Upvote 0
Top