Type mismatch error. Expected Integer, but got Boolean

  1. 2 weeks ago

    Richard A

    Jun 26 Testers, Xojo Pro Puerto Vallarta Mexico

    Why am I getting this compile error:
    -----------
    HLGlobals1.PushBatch, line 152
    Type mismatch error. Expected Integer, but got Boolean
    Select Case ldTot

    Dim ldTot as Integer
    ldTot = (e.TotalSeconds - rs.Field("MemberSince").DateValue.TotalSeconds) /31536000
    Select Case ldTot
    Case 0
      demoTenure.DemographicValue = "Less than 1 Year"
    Case ldTot >= 1 and ldTot < 3
      demoTenure.DemographicValue = "1 - 2 Years"
    Case ldTot > 2 and ldTot < 5
      demoTenure.DemographicValue = "3 - 4 Years"
    Case ldTot > 4 and ldTot < 6
      demoTenure.DemographicValue = "5 Years"
    Case ldTot > 5 and ldTot < 11
      demoTenure.DemographicValue = "6 - 10 Years"
    Case ldTot > 9 and ldTot < 21
      demoTenure.DemographicValue = "11 - 19 Years"
    Case ldTot > 20 
      demoTenure.DemographicValue = "20 Years or more"
      
    end
  2. Markus R

    Jun 26 Testers, Xojo Pro Europe / Germany / Lower Saxon...
    Edited 2 weeks ago

    i guess your condition return true/false
    its more select case true

  3. Tim P

    Jun 26 Testers, Xojo Pro Rochester, NY

    I think it might be that Case ldTot > 2 and ldTot < 5 evaluates out to a boolean, but the select case is an integer. You need to use the to keyword to evaluate as an integer.

    Try something like this:

    select case ldTot
    case 0
      demoTenure.DemographicValue = "Less than 1 Year"
    
    case 1, 2
      demoTenure.DemographicValue = "1 - 2 Years"
    
    case 3, 4
      demoTenure.DemographicValue = "3 - 4 Years"
    
    case 5
      demoTenure.DemographicValue = "5 Years"
    
    case 6 to 10
      demoTenure.DemographicValue = "6 - 10 Years"
    
    case 11 to 19
      demoTenure.DemographicValue = "11 - 19 Years"
    
    case else
      demoTenure.DemographicValue = "20 Years or more"
      
    end
  4. Rick A

    Jun 26 Testers, Xojo Pro (Brazil. UTC-3:00)
    Edited 2 weeks ago

    Or just use the good IF. Not your case, but if you were dealing with fractions, a Select Case would not fit well.

      If ldTot < 1 Then
        demoTenure.DemographicValue = "Less than 1 Year"
        
      ElseIf ldTot >= 1 and ldTot < 3 Then
        demoTenure.DemographicValue = "1 - 2 Years"
        
      ElseIf ldTot > 2 and ldTot < 5 Then
        demoTenure.DemographicValue = "3 - 4 Years"
        
      ElseIf ldTot = 5 Then
        demoTenure.DemographicValue = "5 Years"
        
      ElseIf ldTot > 5 and ldTot < 11 Then
        demoTenure.DemographicValue = "6 - 10 Years"
        
      ElseIf ldTot > 10 and ldTot < 20 Then
        demoTenure.DemographicValue = "11 - 19 Years"
        
      ElseIf ldTot > 19 Then
        demoTenure.DemographicValue = "20 Years or more"
      End
  5. Dale A

    Jun 26 San Diego, California, USA

    I think that you are seeing the issue because the Case statement arguments are being evaluated as Booleans.

    Case ldTot >= 1 and ldTot < 3

    evaluates as if condition 1 is true and if condition 2 is true then... but since you're specifying integer as the select basis, you get the error.

  6. Norman P

    Jun 26 Testers, Xojo Pro outside admiring the sunshine,...
    Edited 2 weeks ago

    your cases, while checking an integer, give a TRUE FALSE result
    (is the value in this range etc)

    so use SELECT CASE TRUE and it will pick the first one where the expression is TRUE

    Dim ldTot as Integer
    ldTot = (e.TotalSeconds - rs.Field("MemberSince").DateValue.TotalSeconds) /31536000
    
    Select Case true
    Case ldTot = 0 // <<<<<<<< this one changed
      demoTenure.DemographicValue = "Less than 1 Year"
    Case ldTot >= 1 and ldTot < 3
      demoTenure.DemographicValue = "1 - 2 Years"
    Case ldTot > 2 and ldTot < 5
      demoTenure.DemographicValue = "3 - 4 Years"
    Case ldTot > 4 and ldTot < 6
      demoTenure.DemographicValue = "5 Years"
    Case ldTot > 5 and ldTot < 11
      demoTenure.DemographicValue = "6 - 10 Years"
    Case ldTot > 9 and ldTot < 21
      demoTenure.DemographicValue = "11 - 19 Years"
    Case ldTot > 20 
      demoTenure.DemographicValue = "20 Years or more"
      
    end
  7. Alberto D

    Jun 26 Testers, Xojo Pro Austin, Texas

    Tim and Rick fixed the original code (related to ranges):

    ldTot > 9 and ldTot < 21

    is for 10 - 20 years and not 11 - 19 years

    ldTot > 20

    is for 21 Years or more and not 20 Years or more

    Just FYI.

or Sign Up to reply!