REQUEST A DEMO

App.ShowSolution in ClearBasic

I’m sure most of the ClearBasic brainiacs already know this (and I may have at one point), but the parameter to App.ShowSolution is a record of type "workaround", not a record of type "probdesc".

I probably knew this at one time, but its been a long time since I’ve done ClearBasic coding. I’m blogging this so that I can find it again in the future, with Google’s help, of course.

 

If you call App.ShowSolution with a probdesc record, you get this ever-so-helpful pile of joy:

error

Cannot map specific relation (type 1 with relation -3).

Uh, yeah. Thanks. No, really. That was a helpful message. I’m in awe of your ability to render something so utterly useless. Freakin’ programmers.

 

Working code example:

Sub ShowObject(objectType As String, idNumber As String)
    If objectType = "solution" Then objectType = "probdesc"

    Dim br As New BulkRetrieve
    br.SimpleQuery 0, objectType
    br.AppendFilter 0, "id_number", cbEqual, idNumber

    ‘For solutions, we need to get the related workaround (the first one will do)
    If objectType = "probdesc" Then
        br.TraverseFromParent 1, "probdesc2workaround", 0
    End If

    br.RetrieveRecords

    Dim listOfRecords As List
    Set listOfRecords = br.GetRecordList(0)

    If listOfRecords.Count = 0 Then
        App.MsgBox "Unable to locate ‘" & objectType & "’ with id of " & idNumber
        Exit Sub
    End If

    Dim recObject As Record
    Set recObject = listOfRecords.ItemByIndex(0)

    If objectType = "case" Then
        App.ShowCase recObject
        Exit Sub
    End If

    If objectType = "probdesc" Then
        Set listOfRecords = br.GetRecordList(1)
        Set recObject = listOfRecords.ItemByIndex(0)    
        App.ShowSolution recObject
        Exit Sub
    End If

End Sub