VB.NET Can't See Subroutine (Beginner Question)

Hey, I'm new to VB.NET.

I have a form where a menu entry is trying to call a subroutine in another file.

I created a Class file with the contents as follows -

Imports Microsoft.VisualBasic
Public Class CodeFile1

    Public Sub InitializeSymbolLoad()

        Stop
        Return

    End Sub

End Class

No matter what I do, I can't "see" the Sub InitializeSymbolLoad from the form.

Pretty basic, I know. Maybe I shouldn't put the routine in a "Class".

Any suggestions?
gbmcneilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You created an instance method, which means you have to have a valid instance to call the method against:

e.g.

Dim cf As New CodeFile1()

cf.InitializeSymbolLoad()

Open in new window


Another alternative would be to make the method Shared:

Public Class CodeFile1

    Public Shared Sub InitializeSymbolLoad()

        Stop
        Return

    End Sub

End Class

Open in new window


...so that you do not require an instance. You instead call the method against the class name:

CodeFile1.InitializeSymbolLoad()

Open in new window


A final option, at least in VB.NET, would be to put the method inside of a Module rather than a Class. You should then be able to see the method throughout your project (I can't remember if you need to still prefix the method with the class name, but I don't think you do.).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gbmcneilAuthor Commented:
I wrote you a long, detailed message - then lost it when I accepted your solution.

Thanks very much for your help.
0
käµfm³d 👽Commented:
No worries!  As long as you got it sorted out  = )
0
gbmcneilAuthor Commented:
Yes, I combined the keyword "Shared" in my subroutine with the CodeFile1.InitializeSymbolLoad() call.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.