vbavb6recordset

VB6 data match a recordset current record to an Array and get description text


I have table called beacons which has PrimaryCode, SecondaryCode and Description I need to retrieve the full code from aonther table called data and split that code into Left$ and Right$ so that it matches the PrimaryCode and Secondary code, then I can get the Description. The full code is 000A0A003 so the left I capture 6 chars and the right I capture 3 chars from the Access current record to find a match in the array ABeacons.

I have tried this but no good

If IsEmpty(VcurrentRecord(0).VOBeaconCodePrimary) = False Then
    fullvalue = (VcurrentRecord(0).VOBeaconCodePrimary)
    leftvalue = Left$(VcurrentRecord(0).VOBeaconCodePrimary, 6)
    rightvalue = Right$(VcurrentRecord(0).VOBeaconCodePrimary, 3)

    If ABeacons(I).PrimaryCode = leftvalue Then
        'MsgBox ("found left value" & leftvalue)
        If leftvalue = ABeacons(I).PrimaryCode And rightvalue = ABeacons(I).SecondaryCode Then
            MsgBox (ABeacons(I).Description)
        End If
    End If
End If

Solution

  • You probably want to loop through the values in your ABeacons array to look for a match:

    If IsEmpty(VcurrentRecord(0).VOBeaconCodePrimary) = False Then
        fullvalue = (VcurrentRecord(0).VOBeaconCodePrimary)
        leftvalue = Left$(VcurrentRecord(0).VOBeaconCodePrimary, 6)
        rightvalue = Right$(VcurrentRecord(0).VOBeaconCodePrimary, 3)
    
        Dim iCounter As Integer
        For iCounter = LBound(ABeacons) To UBound(ABeacons)
            If ABeacons(iCounter).PrimaryCode = leftvalue Then
                If leftvalue = ABeacons(iCounter).PrimaryCode And rightvalue = ABeacons(iCounter).SecondaryCode Then
                    MsgBox(ABeacons(iCounter).Description)
                End If
            End If
        Next
    
    End If