Results 1 to 4 of 4

Thread: passing structures between modules

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    75

    passing structures between modules

    i have a main module called "main", within the module i have declared 2 other modules "Interfacing" and "Espec", within these 2 submodules they both have a structure called "coord" which is identical. The problem is that when i have defined a function in one module with "coord" as type and try to assign a value in the other module with coord type i get error message "Value of type Main.Interfacing.Coord cannot be converted to Main.Espec.Coord", so basically how could i pass that structure?

    sample code:
    Code:
    <module "Main">
    Public Interfacing as new Interfacing
    Public Espec as new Espec
    
    <module "Interfacing">
    Public Structure Coord
        public x%
        public y%
    End Structure
    Public Function getcoord(byval someparameter%) as coord
        'assign values n stuff
        return getcoord
    end function
    <module "Espec>
    Public Structure Coord
        public x%
        public y%
    End Structure
    Public Sub Something()
        Dim somevalue as coord = main.interfacing.getcoord(someparameter)
    End Sub

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: passing structures between modules

    I think you just need to specify the full name. The full name is Main.Interfacing.Coord or Main.Espec.Coord, but you can usually shorten this to just Coord.

    However, just Coord is now ambiguous (it could mean Main.Interfacing.Coord or Main.Espec.Coord), so usually VB will not be able to decide which of the two you mean.
    If, however, you use Coord in the same class that its declared in, VB will assume that you mean the Coord in that same class. So, for example, if you use just 'Coord' in the Espec class, VB will assume that you mean Main.Espec.Coord. If you actually mean the other one, all you need to do is specify the full path (Main.Interfacing.Coord) to tell VB that you meant the other one.


    That said though, I see no reason to have the exact same structure in two different places. Can't you just declare it outside of these classes, so that both classes use the same structure?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    75

    Re: passing structures between modules

    well i got it working alltho im not perfectly happy with it, in the end i declared coord struct in main module and used main.coord in both submodules. The reason i want to declare them in both is coz im a big fan of modularity and want both subs to be able to operate as stand alone things aswell, basically the interfacing module is more like a framework that automates lower level stuff for the espec module which does the mid level thinking and the main module just calls the shots from the most superficial level and holds up the visual front

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: passing structures between modules

    Then it makes sense to put the Coords structure in the Interfacing module only, and simply use that from the other top-level modules. Of course, you the cannot use the Espec module without the Interfacing module (but you can use the Interfacing module without the Espec module, but with some other 'top-level' module).

    This is just how the .NET framework works, for example. All classes and structures you use are part of the .NET framework, and your own modules and classes are another layer on top of that. That layer uses the classes from the layer below. You cannot use your own classes without the .NET framework, just like you cannot use the Espec module without the Interfacing module.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width