Link to home
Start Free TrialLog in
Avatar of Unimatrix_001
Unimatrix_001Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Error: Expression is not a method

Hi,

From the below code, the problem I'm having is on the second last line starting with DirectCast - I'm placing an object into CObjectManager and attempting to get it back casting it to a CTest class but the error I'm getting is:

"Expression is not a method."

I would appreciate some insight.

Thanks,
Uni
Public Interface IObject
End Interface
 
Public Class CTest
    implements IObject
    //Misc methods.
End Class
 
Public Module CObjectManager
    Private activeObject As IObject
    //set and get methods for activeObject
End Module
 
Public Sub Main()
    Dim testObject as New CTest
    CObjectManager.setActiveObject(testObject)
    DirectCast(CObjectManager.getActiveObject(), CTest).CTestMethods()
End Sub

Open in new window

Avatar of The_King
The_King

the way you have formatted
DirectCast(CObjectManager.getActiveObject(), CTest).CTestMethods()
is what you do to run a METHOD i.e.... Screen().ClearScreen()  would be a method to clear the screen (A Method does something)

you need to format an expression for example

SOMETHING = DirectCast(CObjectManager.getActiveObject(), CTest).CTestMethods()

hope this helps

Is CTestMethods your data type you want the data to be mapped into.

if it is then you need

CTestMethods = DirectCast(CObjectManager.getActiveObject(), CTest)
Avatar of Unimatrix_001

ASKER

Hi there,

Hm, I am not understanding this very well. See, my class is CTest that's what I'm wanting to typecast into. So I could do something such as:

CTest returnedValue=CObjectManager.getActiveObject()

But clearly I cannot do that (can I???) because getActiveObject returns an IObject, which needs to be cast.

Thank you,
Uni
ASKER CERTIFIED SOLUTION
Avatar of The_King
The_King

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh I read your code now

you want it in variable testObject right?

testObject = DirectCast(CObjectManager.getActiveObject(), CTest)
That's lovely - thank you. :)