I know but it need to Initialize library,I guess you could create a class containing the function, then compile it to a library.
- Colin.
I love built-in function.Well in that case I don't think you can do it. As far as I know, the only ways are:
1) Create a class, compile it to a library then initialize an instance of the library to call the sub (eg: library.sub);
2) Create a class & declare a Public Sub, then initialize an instance of the class to call the sub (eg:class.sub);
3) Create a code module & declare a Public Sub, then call the sub from another module, activity or service (eg: module.sub);
4) Create an activity or service & declare a Public Sub, then call it from another module, activity or service (eg: CallSub(activity/service, "sub").
I don't think there's any way to create a globally visible sub & access it without a reference to the class, module, service or activity that it resides in. In fact, I can't think of a way of doing that in any of the languages I code in. Eg: even if you create an extension or singleton in Swift, you still have to use a reference to the class or type that it's declared in to access it.
Why do you need to access it like a built-in function?
- Colin.
I love built-in function.
I dont want to use module.sub
Actually I want to use sub directly,maybe?
Ok thanksThe only way to do that is to declare the sub in the same module as you are calling it from - but you would still need to use module.sub to call it from outside that module (as far as I know).
- Colin.
Code modules can not have events. Code modules is most probably not the right place.The only way to do that is to declare the sub in the same module as you are calling it from - but you would still need to use module.sub to call it from outside that module (as far as I know).
Add the sub to your activity if you want to use it directly. If you want to use the sub from another activity; add the code to this acivity TOO.Actually I want to use sub directly,maybe?
Code modules can not have events. Code modules is most probably not the right place.
Service, Activity or Classes. I would like to suggest to create a class.
You are right, sorry. Yes that´s what i meantI think you mean code modules can't handle events
Yes Yes it is good solution.Who is author of Core lib?Probably it is treated differently, but the Core library allows what @devmobile would like to do.
The author of Core lib could say this: who is he?![]()
I was kidding: he is ErelYes Yes it is good solution.Who is author of Core lib?
Who is author of Core lib?
Yes, "Anywhere Software" is a more correct answer.Anywhere Software
There was a similar question some months ago but now I can't find it.Sometimes I seemed to see libraries that did not need initialization and that you could call their routines directly.
Dim a as int=3
Dim b as int=4
myUtils.function1(a,b) '<-- no need to instantiate (nor initialize) anything before.
That's right. The trick is to compile the library with the same name as the code moduleUsing a routine directly can also be a problem: you do not know which library contains that routine!
In the case of a code module compiled as library you do not know the name of the code module.
Have to write something like:
MyLibrary.DoSomething
lets you know (when you will read your source code after years) which library exposes DoSomething.
If you have / need a single code moduleThat's right. The trick is to compile the library with the same name as the code module![]()