locked
Programmatically work with a module RRS feed

  • Question

  • I have a need to work with two different web service providers. To do this I have created a module for each provider and of course the modules contain the different functions to work with its provider.

    I would like to reference variables (get and set) within the different modules programmatically with a single instance of code. Example

    Instead of explicitly stating:

    Public ClassForm1 

    Private SubButton1_Click(sender As Object, e AsEventArgs) HandlesButton1.Click     

         module1.v_variable1 = "Some text"

         module2.v_variable1 = "Different text"   

    EndSub

    End Class

    I would like to perform something like:

    Public ClassForm1 

    Private SubButton1_Click(sender As Object, e AsEventArgs) HandlesButton1.Click     

         mymodule = my.settings.processor ' This is the name of the processor and is currently an application string variable

         mymodule.v_variable1 = "Some text"

    EndSub

    End Class

    I have not been able to determine how to reference the module and its variable programmatically.

    Thank you in advance for your help.

    Wednesday, December 19, 2018 5:05 AM

All replies

  • How do you determine which module you want to use? Is this set by the user during application installation or what?

    " mymodule = my.settings.processor ' This is the name of the processor and is currently an application string variable"

    How and when does this get set?

    Give a more complete word example of exactly what you plan to/want to do.

    Does the user select the web service you want? The you use a module based on that? Is this then saved in settings?

    Wednesday, December 19, 2018 6:51 AM
  • Hi,

    Do you want to use this Module through the Module name(string)?If it is a class, it can be realized by reflection.

     Public Function GetInstance(Of T)(ByVal instanceName As String) As T
            Return CType(Assembly.Load(Assembly.GetAssembly(GetType(T)).GetName().Name).CreateInstance(GetType(T).[Namespace] & "." & instanceName), T)
        End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 19, 2018 7:05 AM
  • Have you considered having base functionality in a class then have a class for each provider that resides in it's on namespace?

    Well this is not a web service but should get the idea across.

    Public Module Example
        Public Sub Demo()
            Dim cust1 = New First.Customer
            cust1.Demo()
    
            Dim cust2 = New Second.Customer
            cust2.Demo()
        End Sub
    End Module
    
    Public Class Person
        Public Property Id() As Integer
        Public Property FirstName() As String
        Public Property LastName() As String
    End Class
    Namespace First
        Public Class Customer
            Inherits Person
    
            Public Function Demo() As Boolean
                Return True
            End Function
    
        End Class
    End Namespace
    Namespace Second
        Public Class Customer
            Inherits Person
    
            Public Function Demo() As Integer
                Return 10
            End Function
        End Class
    End Namespace
    
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, December 19, 2018 8:37 PM