Click to See Complete Forum and Search --> : How do you add a global import to the code?


tccbama1
January 26th, 2004, 10:58 PM
I am coding in Visual Basic .NET and I am trying to code a global import. Can anyone help me with the proper syntax to use in the code? Maybe even provide a sample code for demo purposes?

Thanks
:D

dtv
January 27th, 2004, 02:11 AM
'global import' is the 'reference'. The 'Imports' keyword is file-based, the only way to make it work for all of your code parts is to put in a .vb file ALL of your modules, classes etc. (1)

Another way is to Import your public library in a module and then make inherited classes with no-addons from the sources, or just public subs/functions in which you can use their functionality with only the sub's names, without referencing to the whole lib name. (2)

'(1) ".vb filename=myEntireProjectInAvbFile.vb"
Imports libGlobalLibrary

Public Class Form1 'the startup form must be at the top of the file
...
End Class

Public Module Module1
...
End Module

Public Structure IntegerPlus
...
End Structure

'(2)=make lib's functionality public through public functions
'put this in a standard module (.vb file)

Imports libGlobalLibrary

Public Function GetNewInstanceOfMyClass1() As MyClass1
Return New MyClass1
End Function

'but you have to deal with it as an Object outside this module, unless if you use:
'Private cls1 As libGlobalLibrary.MyClass1 = GetNewInstanceOfMyClass1() 'I dont like that idea
'better to make Public instances, if you will going to need less than two instances of each of your classes

Public cls1globalInstance As New MyClass1 'it is accesible from all of your vb modules
...


There may be more ideas, I hope this will do for now.

tccbama1
January 27th, 2004, 09:25 PM
Thanks for info on the global import it helped!!!

:thumb: