Click here to Skip to main content
15,072,051 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In this code that the conversion of the long is not converted in to the long so please help to solve this the error position is shown in the bold character .

VB.NET
Public Function GetFacetCount(reader As IndexReader, queryFilterOnMainQuery As Filter) As Int32
           Dim bs = GetValueBitset(reader)
           bs.InPlaceAnd(queryFilterOnMainQuery.GetDocIdSet(reader).Iterator())
           If DirectCast(bs.Cardinality(), Int32) >= 1 Then
               Return DirectCast(bs.Cardinality(), Int32)
           Else

               Return 0
           End If
       End Function
   End Class


What I have tried:

Dim bs = GetValueBitset(reader)
bs.InPlaceAnd(queryFilterOnMainQuery.GetDocIdSet(reader).Iterator())
Dim Cardinality As Integer = Convert.ToInt32(bs.Cardinality())
If Cardinality >= 1 Then
Return Cardinality
End If
Posted
Updated 18-Feb-16 23:29pm

What is the return type of bs.Cardinality()? I assume a Long?

Because you would then be narrowing the value (from 64bit to 32bit) you need to use CType (see link). Also, you must ensure that the Long value doesn't overflow the Integer value after narrowing because it would still fail otherwise.

CType Function (Visual Basic)[^]

Above would maybe "fix" it, but... You need to ask yourself why you try to force the result type in a possible incompatible type? If the result of the function is a Long, why not store and use it as a Long? The person who created the function returns a Long value probably because the value could be very large. Because you simply check if the value is larger or equal to one you can easily use a Long or whatever the result type is without any problems. You should only use narrowing or widening if absolutely necessary.

Good luck!
   
Comments
Member 11835578 19-Feb-16 5:36am
   
thanks sir

can you ans this question of below link
http://www.codeproject.com/Questions/1079780/Error-conversion-from-string-reference-to-type-dou
Have you tried to use
VB
Return CInt(bs.Cardinality())


to do the Type conversion in VB??

Ref.: Type Conversion Functions (Visual Basic)[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900