Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Collection of my own type

Collection of my own type

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jerome Conus
    wrote on last edited by
    #1

    Hi ! Using VB6, in a standard EXE app, I'm trying to add in a collection elements of my own type : Option Explicit Private m_colMyCol As Collection Private Type MyType lLong As Long iInteger As Integer sString As String End Type Private Sub Form_Load() Dim l_lRec As MyType Set m_colMyCol = New Collection l_lRec.iInteger = 1 l_lRec.lLong = 10 l_lRec.sString = "Hello" m_colMyCol.Add l_lRec MsgBox m_colMyCol.Count End Sub When I run this sample code, I get this error : 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 I tried to put the type declaration as Public in a module, but I still get the same message. Anyone got an idea what I'm doing wrong ? Thanks ! Jerome

    M 1 Reply Last reply
    0
    • J Jerome Conus

      Hi ! Using VB6, in a standard EXE app, I'm trying to add in a collection elements of my own type : Option Explicit Private m_colMyCol As Collection Private Type MyType lLong As Long iInteger As Integer sString As String End Type Private Sub Form_Load() Dim l_lRec As MyType Set m_colMyCol = New Collection l_lRec.iInteger = 1 l_lRec.lLong = 10 l_lRec.sString = "Hello" m_colMyCol.Add l_lRec MsgBox m_colMyCol.Count End Sub When I run this sample code, I get this error : 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 I tried to put the type declaration as Public in a module, but I still get the same message. Anyone got an idea what I'm doing wrong ? Thanks ! Jerome

      M Offline
      M Offline
      mikasa
      wrote on last edited by
      #2

      Yes, it can't be done. The only way I was able to do this was to Create a simple Class module and store the Class Objects within the Collection. 1.) Create a Class in your App. 2.) Create the Properties Public ID As Long Public intCounter As Integer Public Key As String That's it! Just create new instances of the class and store them in the Collection.:)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups