Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call functions or subs from different files

Status
Not open for further replies.

arneweise77

Programmer
Apr 25, 2002
46
SE
Hi! I want to access functions from another file then the .aspx file that´s running. I´m using vbscript

Thanks
Arne
 
Are you talking about a script or a class method from another aspx.vb file?

As far as class methods:
All forms in VB.net are classes, and to call a method from another class you either need an instance of that class or the method needs to be "shared" which means it doesn't operate on a specific instance of the class. If it's a shared method you can call it using class.method syntax.

Good luck!
TealWren
 
Just to add to what Teal talked about, you can also create a Module file. This is just like a module file in VB where you can write subs and functions, declare them public, and have them available from the entire project. The bonus with a module is that you don't need to create a class to use them, you just call the sub/function directly.

Jack
 
Hi Jack!
Can you give an example on how to create a module file, I´m new to vbscript and vb. I´m used to c/c++.
Please help
Arne
 
Hey Arne,

There's two ways to do it:

Using Visual Studio:
1. open your project
2. right click your project and select Add New Item...
3. one of the options will be a Module file. select it and
click OK

Not Using Visual Studio
1. Open notepad or whatever text editor you're using
2. Enter this text:
Module ModuleName

End Module
3. Save it with a .vb extension

vb.net is kewl in the sense that you just define what you are creating within one code file. In vb6.0, you had different files for modules, classes, etc. Now, there are just generic code pages (you'll notice that class files, modules files, etc all have .vb as an extension), so to create a class or a module you just have to specify the syntax. Very cool

Hope this helped.
:)

Jack
 
Thanks Jack!
But I still need some more explinations. I´ve made a Module of the file and renamed with .vb extension. But from the .aspx file, that I want to call the functions from the .vb file, I must do some kind of include to let the .aspx file know that I´m calling for a function in the .vb file.

And don´t I need to some kind of precompiliation of the .vb file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top