Fld.FindSingle problem

Joakim Schramm joakim at astrocalc.com
Mon Sep 18 11:32:34 CDT 2006


> 
> This is wrong idea. Actually we will improve the situation 
> with IVSet, IVArraySet and IVSet, but currently it should be 
> something like this:
> 
> ...
> Dim arrEditBody As VArraySet
> Dim mResult As VBitSet
> 
> Set arrEditBody = lnk.FindLinked(mConfNum, tblConf, tblText)
>   
> ' Just make an empty bitSet
> Set mResult = tbl.SelectNoneRecords
> Set mResult = 
> mResult.InitWithArraySet(tbl.PhysicalRecordCount(), arrEditBody)
> 
> Call fldKey.ValueExistsWithCount(sKey, cnt, mResult) ...
> 
Hi,

Doesn't work! I may need to clearify one thing, it's not that it doesn't
select/return a record, it's that it returns the wrong record. Also with
your code above I get the same result. The table has 3 records with value of
sKey, arrEditBody only has 1, the third of those 3, the result returned is
the first record of table NOT of record set.

I will paste full code below for concerned parts. You will see test code
with VSET.Count return 1, while ValueExistsWithCount return 3

'Module declarations
Private tblConf     As VTable
Private fldConfName As VField
Private fldType     As VField
Private tblText     As VTable
Private fldKey      As VField
Private fldBody     As VField
Private fldLevel     As Vfield
Private arrEditBody As VArraySet
Private mConfNum As Long
Private mCurrRec As Long
Private EditRange As Long

'procedures
Private Sub InitFields()
    With mTextDB 'Global
        Set tblConf = .Table("Config")

        With tblConf
            Set fldConfName = .Field("Name")
            Set fldType = .Field("Type")
        End With

        Set tblText = .Table("TextBlock")

        With tblText
            Set fldKey = .Field("Key")
            Set fldBody = .Field("Body")
            Set fldLevel = .Field("Level")
        End With
    End With

End Sub

Private Sub cboConfig_Click()

With cboConfig

    If .ListIndex <> -1 Then
        mConfNum = .ItemData(.ListIndex)
        Call PutIniVal(INIMPS, "LastConfig", CStr(mConfNum), sIniFileTxt)
    Else
	...
    End If
	...
End With
End Sub

Private Sub optEditRange_Click(Index As Integer)
Dim lnk       As VLink
Dim sLinkName As String

'Exist 3 bin links between tblConf and tblText. 
'Each linked 1:M were 1,2 and 3 together makes up a "group" of records.
'This code deside which link to use

EditRange = Index
sLinkName = "lnkBlockLevel" & CStr(EditRange)
Set lnk = mTextDB.Link(sLinkName)
Set arrEditBody = lnk.FindLinked(mConfNum, tblConf, tblText)
...
GetEditText
End Sub


Private Sub GetEditText()
Dim sKey As String
Dim mResult As VBitSet
Dim cnt As Long
Dim mVset As Vset

'In this case EditRange is 0 - but same result with 1 & 2
Select Case EditRange
    Case 2
        sKey = StrMakeKey(AspPlan, Plan1, Plan2)
        lblTextHeader.FontName = AFont
        lblTextHeader.Caption = PlanetSymbols(AspPlan) & "=" &
PlanetSymbols(Plan1) & "/" & PlanetSymbols(Plan2)
    Case 1
        sKey = StrMakeKey(Plan1, Plan2)
        lblTextHeader.FontName = AFont
        lblTextHeader.Caption = PlanetSymbols(Plan1) & "/" &
PlanetSymbols(Plan2)
    Case 0
        sKey = "000"
        lblTextHeader.FontName = MsFont
        lblTextHeader.Caption = fm(545)
End Select

' Just make an empty bitSet
Set mResult = tblText.SelectNoneRecords
Set mResult = mResult.InitWithArraySet(tblText.PhysicalRecordCount(),
arrEditBody)
Set mVset = mResult
Debug.Print mVset.Count ' = 1

Call fldKey.ValueExistsWithCount(sKey, cnt, mResult)
'cnt = 3
If Not mResult Is Nothing Then
    'here ALWAYS firstrecord matching sKey in tblText is returned
    mCurrRec = fldKey.FindSingle(sKey, mResult)
Else
    mCurrRec = 0
End If

If mCurrRec <> 0 Then
    tblText.RecID = mCurrRec
    txtEdit.Text = cStringSAR(fldBody.GetString, Chr$(255), vbNewLine, 0)
Else
    txtEdit.Text = vbNullString
End If

End Sub

I hope this help to see it better. By the way, I also tested with your local
Dim's and same result.

Joakim



More information about the Valentina mailing list