Listbox cellValueAt

Hi
I’m just getting back into Xojo after a while, trying to load a log file and display it in a list box with colour coded rows.
I’ve got the log file loaded into an array and can populate the listbox but in the CellBackgroundPaint event am unable to get the value of one of the cells ( INFORMATION, WARNING, ERROR).

In the code below, the debugger shows that the String 'logType 'is showing as INFORMATION, but the integer ‘deleteInteger’ is always coming up as -1, and so the cells never actually get assigned a colour because none of the Cases are greater than -1.

Can anyone see where I’m going wrong.

 #Pragma Unused column

If row >= Me.RowCount Then Return False

Var logType As String = me.CellValueAt(row,1)
var deleteInteger as Integer = logType.indexOf("INFORMATION") //variable for debugging only

Select Case true
  
case logType.indexOf("INFORMATION") >= 0
  g.AntiAlias = False
  g.DrawingColor = &cb2e89b
  g.FillRectangle(0,0, g.Width, g.Height)
  
  
case logType.indexOf("INFO") >= 0
  g.AntiAlias = False
  g.DrawingColor = &cb2e89b
  g.FillRectangle(0,0, g.Width, g.Height)
  
case logType.indexOf("DEBUG") >= 0
  g.AntiAlias = False
  g.DrawingColor = &cafcced
  g.FillRectangle(0,0, g.Width, g.Height)
  
case logType.indexOf("WARNING") >= 0
  g.AntiAlias = False 
  g.DrawingColor = &ced9f64
  g.FillRectangle(0,0, g.Width, g.Height)
  
case logType.indexOf("ERROR") >= 0
  g.AntiAlias = False
  g.DrawingColor = &ceb827f
  g.FillRectangle(0,0, g.Width, g.Height)
  
end Select

Return True

thanks in advance
Paul

If LogType truly contains INFORMATION, then both
INFORMATION
and
INFO should be a match

The return type of CelValueAt is String in the docs, but I have seen comparisons between String and Text fail.

As a test, set

Var logType As String = "INFORMATION"

and run your code.
Does that produce the right values?

Maybe check the text encoding? (usually UTF8 by default, but it wouldnt hurt to force it…)

Is the code getting past If row >= Me.RowCount ?

Also, you may as well have
g.AntiAlias = False
g.FillRectangle(0,0, g.Width, g.Height)

once, outside of the select case… (you only need the select to set the color.)

Thanks Jeff
I already tried defining the string manually like you suggested and it does give me the result I’m after.
When I run my code as is, and have a break point just before the select case, the debugger shows logType is INFORMATION.
I have also tried to force the encoding, I do that when I create the array.

Hi Paul,

I do not understan your code, but anyway, you can simplify it removing from the Select structure:

  g.AntiAlias = False
  g.FillRectangle(0,0, g.Width, g.Height)

and place these lines just before Return True.

And, are you sure you have INFORMATION (as is, and not Information) in your text file ?

Add another variable to hold Me.CellValueAt(row,1) and watch in the debugger what’s in it…

Thanks Emile

Have tried that and it definitely shows as INFORMATION

What does it show the byte values as in the debugger?

have you tried
case LogType.trim = "INFORMATION"

Hi Jeff

shows as encoding utf-8 length 25
trim didn’t do anything

A 12 letter word shows as length 25?

1 Like

Yeah, think that’s where my issue is, I’ll dig deeper.
Thanks for the help, at least I know where to look now.

cheers Jeff

Do not go too deeper (not to the bottom), you have to go back to breathe.

So, where are you now ?

Best guess: this is a UTF-16 string that was defined as UTF-8 and the extra bytes are nulls between the characters. If it’s anything like that, you should fix it at its source, not in this method.

Change the view in the debugger to HEX. See what those 25 chars are. I’m curious.

Thanks for your help everyone, the original file that I was reading was a UTF16LE, changed the encoding of the text input stream and all is working now.

1 Like

Thank you Paul for the update.

Please mark some post as Solution.

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.