Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Assigning a Variant returned value to a public defined type?


Message #1 by "Philip.Ware" <Philip.Ware@e...> on Tue, 27 Jun 2000 18:06:18 +0100
Hi,

I'm having problems trying to create a general function that returns a
public defined type via a variant object:
For example:

Public Type A_Object
	name as string
	ID as integer
End Type

Public Type B_Object
	name as string
	ID as integer
End Type

Public Enum MyObject_Type
	A_type = 1
	B_type = 2
End Enum

Public Sub Format_Result(byval t as MyObject_Type, Result as Variant)

	dim Buffer as string

	' Get buffer data
	Buffer = Get_Buffer_Data(t)

	' format into correct form
	Select case t
	case A_Type
		Result = Format_A_type(Buffer)
	case B_Type
		Result = Format_B_type(Buffer)
	end select

end sub

public function Format_A_type(String) as A_Object
	dim Aobj as A_object

	' format A_object stuff here

	Format_A_type = Aobj
end function

public function Format_B_type(String) as B_Object
	dim Bobj as B_object

	' format B_object stuff here

	Format_B_type = Bobj
end function

Public sub Main_Start()
	
	dim My_A_obj as A_Object

	Format_Result(A_Type, My_A_obj)
	
end sub


I get the following error msg:

"Only public user defined types defined in public object modules can be used
as parameters or return types for public procedures of class modules or as
fields of public user defined types"


Why cant I assign a variant back to my A_Object?

I basically want one function that returns certain objects depending on what
the object type is...
I thought the variant objects were used for this?

Is there a method around? 

Thanks for your help,

Phil


  Return to Index