cancel
Showing results for 
Search instead for 
Did you mean: 

Object Enumerations - Casting 'Current'

Former Member
0 Kudos

I cannot figure out why I receive the error "Specified Cast is not valid." The offending line is marked.


Dim VV_Enum As IEnumerator
Dim oVV As SAPbobsCOM.IValidValue
...
oCB = oForm.Items.Item("CommGrp").Specific
VV_Enum = oCB.ValidValues.GetEnumerator
VV_Enum.Reset()
While VV_Enum.MoveNext
    oVV = VV_Enum.Current           <<< ERROR HERE
    If oVV.Value = oRS.Fields.Item(3).Value Then
        oCB.Select(oRS.Fields.Item(3).Value, SAPbouiCOM.BoSearchKey.psk_ByValue)
    End If
End While

If VV_Enum.Current Is Nothing Then
    oApplication.SetStatusBarMessage("The Commission Group '" & oRS.Fields.Item(4).Value & "' is no longer active.  You must save it to an active commission group.", SAPbouiCOM.BoMessageTime.bmt_Medium, True)
End If

I have tried defining oVV as an SAPbobsCOM.ValidValue. As well, I've tried explicit casting using CType(). No luck. I am simply trying to run through the list of values in a drop down object to see if a particular value (which is saved in a recordset from a previous SQL query) matches any of these values.

Thank you for your assistance in advance!

Accepted Solutions (1)

Accepted Solutions (1)

bruno_peyron
Active Participant
0 Kudos

... plus I think your logic is broken. It seems to me you'd need an <tt>Exit While</tt> in the <tt>If</tt> branch.

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you. Your coaching was precisely correct.

Scott

bruno_peyron
Active Participant
0 Kudos

Glad I could help.

bruno_peyron
Active Participant
0 Kudos

Hi Scott,

I think the problem is you're using the wrong ValidValue class, to wit the one in the SAPbobsCOM library. That one is supposed to represent valid values of user fields (and also those of Recordset fields if I'm not mistaken).

I'd suggest you explicitely used SAPbo<b>ui</b>COM.ValidValue.

Yours,

&nbsp;OC.