I have a situation where I need to query a listbox column to determine the column’s alignment. I version 2019r1.1 I simply used
Dim i As Integer = Listbox1.ColumnAlignment(1) // column 1
But in 2019r2, I changed it to
Dim i As Integer = Listbox1.ColumnAlignmentAt(1) // column 1
and it gives me a Type Mismatch Error with the following verbiage:
Type mismatch error. Expected Integer, but got enum Listbox.Alignments
Dim i As Integer = Listbox1.ColumnAlignmentAt(1)
Is there any way around this?
<https://xojo.com/issue/57826>
Hi Dale,
I found assigning the Enum type directly, rather than Integer, worked for me:
[code]Dim a As Listbox.Alignments = Listbox1.ColumnAlignmentAt(1)
If a = Listbox.Alignments.Center Then
MessageDialog.Show(“Center”)
Elseif a = Listbox.Alignments.Decimal Then
MessageDialog.Show(“Decimal”)
Elseif a = Listbox.Alignments.Right Then
MessageDialog.Show(“Right”)
Elseif a = Listbox.Alignments.Left Then
MessageDialog.Show(“Left”)
Else
MessageDialog.Show(“Default”)
End If
[/code]
I hope that helps.
I’m guessing that one of the objectives of API 2.0 is to move away from allowing Integer values to be used where an Enum exists.
It is more typing, but it makes the code more readable for sure. And it saves one from having to try and memorize or lookup those number values each time.
Dim i As Integer = Integer(Listbox1.ColumnAlignmentAt(1))
and to reverse this
Listbox1.ColumnAlignmentAt(1) = Listbox.Alignments( i )
should do (this is written 100% in the forums so grain of salt and all that)
[quote=457564:@Scott Cadillac]Hi Dale,
I found assigning the Enum type directly, rather than Integer, worked for me:
[code]Dim a As Listbox.Alignments = Listbox1.ColumnAlignmentAt(1)
If a = Listbox.Alignments.Center Then
MessageDialog.Show(“Center”)
Elseif a = Listbox.Alignments.Decimal Then
MessageDialog.Show(“Decimal”)
Elseif a = Listbox.Alignments.Right Then
MessageDialog.Show(“Right”)
Elseif a = Listbox.Alignments.Left Then
MessageDialog.Show(“Left”)
Else
MessageDialog.Show(“Default”)
End If
[/code]
I hope that helps.[/quote]
Scott, thanks but that doesn’t help since I need the actual integer value the enum represents.
[quote=457567:@Norman Palardy]Dim i As Integer = Integer(Listbox1.ColumnAlignmentAt(1))
and to reverse this
Listbox1.ColumnAlignmentAt(1) = Listbox.Alignments( i )
should do (this is written 100% in the forums so grain of salt and all that)[/quote]
Ok, Norman, that works. Apparently it “requires” something that forces the datatype assignment
Dim x As Integer = Listbox1.ColumnAlignmentAt(1) ' Type mismatch error
Dim y As Integer = Integer(Listbox1.ColumnAlignmentAt(1)) ' This works
Dim ss As String = Str(Listbox1.ColumnAlignmentAt(1)) ' This works
Thats referred to as a CAST
Its useful for places where you might need to save some seting since writing an enum to a binary file, plist etc wont work until / unless you convert it to a string, integer etc
Same for where you might read that back in