Camper Camper - 2 months ago 10
Vb.net Question

Returning/Chaining variables vb.net

Id like to have VB.Net code written like this.

Module1.run(parameters,parameters)
">> Passing parameters to module2 >>"
Module2.run(parameters,parameters)

Essentially passing parameters between modules without running a module via a return statement, or multiple statements in this case. And avoiding shared public registers. Is this even possible? Can I pass variables in the module header maybe?

Regards,

Answer

Create a class MyParameters

Public Class MyParameters
    'Add any inputs / outputs
    Public AnInput As Integer
    Public AnOutput As String
End Class

Define Module1.Run as

Public Sub Run(ByVal args As MyParameters)
    args.AnOutput = String.Format("The user passed {0}", args.AnInput)
End Sub

Define 'Module2.Run' as

Public Sub Run(ByVal args As MyParameters)
    Msgbox(args.AnOutput)
End Sub

Then you can call with:

Public Sub Main()
    Dim args = New MyParameters() With {.AnInput = 5}
    Module1.Run(args)
    Module2.Run(args)
End Sub