Help with comp creation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am trying to follow the same structure as the MS Application Blocks for my
local stuff. I am trying to create an application block to process payments
which I'll hand out to other developers in my company. I created the project
Company.Application.Payment and in that project I created one class called
PaymentHelper.vb after compling I created a new project (win form) and then
reference the Company.Application.Payment.dll I then Imports
Company.Application.Payment. The problem is If I create a new sub and then
try

Private Sub CallComp()

PaymentHelper.ProcessPayment()

End Sub

it doesn't work. I have to do the foll

Private Sub CallComp()

Dim test as new PaymentHelper

test.ProcessPayment()

End Sub

Why?
 
You need to make the ProcessPayment method a Shared function in order to
access without creating an instance of the PaymentHelp class. Check out the
Shared keyword in the MSDN docs.
 
Thanks. One question though. Whats the difference on having

PaymentHelper.ProcessPayment()

instead of

Dim test as new PaymentHelper

test.ProcessPayment()

Thanks
 
It depends on what the method does; it it doesn't store any intermdiate data
in the Payment class, there's no difference. However, if it does manipulate
any data in the class, i.e. not saved to a persistent storage such as a file
or a database, then you migth have a problem, in that the class is shared
between multiple callers, and not just the copy you have when you create an
instance of the class. There's more to it than that, but that shoudl give
you an idea.
 
Back
Top