0

Given a simple form, with a multi-column combobox, that gets filled using the code below. Does anyone know why the form returns "-1" instead of "1" for TRUE?

enter image description here

Private Sub UserForm_Initialize()
    loadCellInfoTest
End sub
   Sub loadCellInfoTest()
        With cbxBreakdown
            .Clear
            .ColumnCount = 4
            .ColumnWidths = "70,110,70,600"
            '.value = "Breakdown for: " & targetFormula

            'HEADERS
            .AddItem "Sheet"
            .List(.ListCount - 1, 1) = "Address"
            .List(.ListCount - 1, 2) = "Value"
            .List(.ListCount - 1, 3) = "Formula"

            .AddItem "test"
            .List(.ListCount - 1, 1) = "Address"
            .List(.ListCount - 1, 2) = True  'THIS RETURNS -1
            .List(.ListCount - 1, 3) = "Formula"
        End With
    End Sub
Dumitru Daniel
  • 571
  • 4
  • 19

1 Answers1

2

This is because True is a boolean that converts to -1.

In VBA by definition:

  • True = -1
  • False = 0

In formulas:

  • True = 1
  • False = 0

If you want it as text:

.List(.ListCount - 1, 2) = "True"
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • Thanks for the clarification. I've solved the the issue by defining the variable in which i load the value as String. I'm loading a cell value in the combo-box, and that cell can either have a formula, or be the target of a checkbox. – Dumitru Daniel May 11 '20 at 12:34
  • `cStr(True)` converts it into string too. – Pᴇʜ May 11 '20 at 12:36