Including files in VB.NET

pukya78

Member
Joined
Jun 5, 2006
Messages
15
Programming Experience
Beginner
Hi,
I am a beginner in VB.NET. I have some functions/subs written in a file, say CodeFile.vb. How do I call functions from this file in another file, say Util.vb?

Regards,
P
 
I t doesn't sound like you understand the basics of object oriented programming so let me try to explain. Everything in vb.net is an object (with the possible exception of strings, but we'll leave that for now) In real world terms you can't do anything with an object or the contents of that object unless you own that object. For example.. You wouldn't be able to use car stereo unless you own that car or have access to that car. So in terms of programming you cant use contents of a class/vb.code file unless you own, what we call an instance, of that class/vb.code file. So in order to get access to the functions/subs you have in your code file you must first declare an instance of the class that contains it. For example


VB.NET:
Public class Car 'Here's our car object/class
 
Public CarStereo as string = "The Current Number One" ' Iv'e used a string here just for example purposes
 
End Class
So inside a different Object/class

VB.NET:
Public Class Person' The Person who wants to use that car stereo
 
Public sub PlayCarStereo
messagebox.show(car.playcarstereo)
End Sub
 
End class

So at the moment the person class has a sub routine that can play the car stereo but currently does not own a car so we will get an error. So we need to delcare an instance of the car class inside our person class (essentially that person is going to buy a car)

So we change our percon class to the following..

VB.NET:
Public Class Person
 
Private MyCar as new Car ' We just bought a car (note the 'new' keyword that tells vb that we want a new instance of the car class)
 
public sub PlayCarStereo
Messagebox.show(car.playcarstereo)
End sub
End Class
Now the code will execute and the message box will pop up and display the string value that the carstereo variable holds
 
Hi,
Thanks, I knew all that but still thanks for the help.
Actually, what I had asked was: I have a Class defined in file A.vb and I want to instantiate an object on this class in file B.vb. I was getting an error (which I cant remember now). The problem got solved when I bound that class within a module!

Thanks, P
 
Back
Top