Difference between External, Shared, and Regular Methods?

What’s the difference between the three?

I want to create my own class/module to collect all the custom methods I coded in one place for use in future projects.
But I noticed the autocomplete doesn’t work if I declare a method as regular, while autocomplete works fine if I declare the same method as external or shared.

Please someone describe the difference between the three.

By the way, as a side question:
Which is a better container for collecting custom methods and objects for future use? a module or a class?

An “external” method is for calling a function from an external library, including the system. It’s an alternative to using declare sub or declare function, so it’s not what you’re looking for.

A “regular” method is attached to a class and requires that you create an instance of that class (the most common way of doing that is by using the new keyword). Those methods will certainly show up in auto-complete, but only if prefixed with an instance of that class.

Shared Methods are a way of making methods available within and without the class that do not rely on a particular instance. They are referenced with the class name, not an instance of the class.

As for the broader question of where to put these methods, the answer depends on what you are trying to do. If you want to create general, utility-type function, a module might be a better choice, but usually I recommend creating a class that encapsulates all related code.

Okay so is it a good idea to:

  1. Create class named “Xr”
  2. Put the code inside a PUBLIC shared method, under Xr class.
  3. Name every method starting with “Xr”, for example, XrTimeFormatter

That I can get an autocomplete list of all my methods by writing “Xr”.

Is using PUBLIC for methods a good idea? or is it better to make all methods PROTECTED?

You don’t need to prefix the method names with anything. If you have a class Xr with a method “MyMethod”, you’d call it as Xr.MyMethod anyway. If you make it protected, you’d only be able to use it within that class. As soon as you type “Xr.”, you’ll get a list of methods.

But if all there is going to be in this class are shared methods, i.e., you never plan or need to use dim x as new Xr, you might as well use a module and make the methods public.

Last question:
I created a module name XR.

  1. why I can’t add any shared methods to the module?
  2. autocomplete doesn’t work for the regular method, no matter public(methodname) or protected (XR.methodname)

That’s strange…

I created a new project, did the same, and autocomplete WORKS.
But it doesn’t work in my app’s project :frowning:
Why?

Not sure if it’s relevant or not. but here’s the code inside the method:

[code] dim mins, secs as string

// convert time into mm:ss format
mins = format(time/60 , “##”)
secs = format(time Mod 60, “##”)

return mins+":"+secs[/code]

and configurations:

name: FormatTime_mm_ss
parameters: time as integer
return type: string
scope: protected

There is no such thing as a Shared Method in a module. You should really consult the documentation for a better explanation, but a Shared Method is only available in a class to distinguish between those methods that act within the context of an instance and those that don’t. In a module, if the method is marked as Global or Public, it is already “shared”.

The code you described is a function, as distinguished from a sub(routine). The difference is that a function returns a value while a sub does not, and auto-complete is intelligent enough to know when each is appropriate. If you start typing “Xr.F” to start a line, auto-complete knows that only subs are appropriate there, and only presents those. On the other hand, if you type “dim s as string = Xr.F”, it knows you are accessing a function and present a list of those.

Really really really tnx this time!
I learned an important thing about autocomplete, that I thought was a bug before knowing!!