Methods, strategy for using along the project

Greetings to the season! All of you!

I think my project don’t differ from any other project in this sense:
Window1

  • Method1
    Window2
    Window3

Makes sense, right?

In Window3, button "Show Message": MsgBox Window1.Method1 + Window1.Method1 + "secret message" + Window1.Method2 + Window1.Method2

When compiling and pushing the button “Show message”, Window1 open!!
Apparently, you can not store Methods in one place and use them all over the project!?
How do you solve these things!? What am I missing!?

[quote=155347:@Jakob Krabbe]Greetings to the season! All of you!

I think my project don’t differ from any other project in this sense:
Window1

  • Method1
    Window2
    Window3

Makes sense, right?

In Window3, button "Show Message": MsgBox Window1.Method1 + Window1.Method1 + "secret message" + Window1.Method2 + Window1.Method2

When compiling and pushing the button “Show message”, Window1 open!!
Apparently, you can not store Methods in one place and use them all over the project!?
How do you solve these things!? What am I missing!?[/quote]

Drag a module into your project and move the method into it. Then you make the method global and you can use it anywhere.

Ah!
That’s a strategy, indeed!!
I was not aware of that, that’s all new for me!
Thank you!

In the mean time, I’ll try to think of a good name for this “Module1”…! Ha!

You need to think carefully about where to place a method and its scope over your application.

Ask yourself these questions before creating the method :

Where should it be used? Only in one particular location (can be a Window, module, class) or in more locations?
If in more locations, place it in a module and make it global. However I find it a better way to make it protected, because then you have to put the name of the module in front of the name.
For example : module name “Vars” contain method “Init”. So it is better to write Vars.Init when you call that method from somewhere else than just making it global. Making it global can lead easily to mistakes because when overlooked, you can have two methods with the same name.

If it is used in only one Window or Module, then it is better to place that method inside them and make it private.

In the past I used a lot of classes and functions in my applications. However in many conditions I found it easier and much clearer to use classes which on their turn contain their own methods and functions.

It is all about personal preference. Try to create your applications with clean design in mind, so you can easily find your way around. Give clear names to modules, methods, objects, Windows, classes and so on, which helps you remembering their uses.

Hope this helps.

OK, thank you!
Yes, it helps…!

I shall make Methods Private, not Global as Global can generate misunderstandings all along.
I’m not a King of Modules… sort of!
I’m still waiting for this day to arrive!!

This is all new for me.
However, there are many things as I don’t know about and my strategy in life is only to get involved and learn things that I actually need. Not things “that may be needed”, sort of…

I can live with that!
As long as it works I’m happy!

Thank you!
I’ll stick with Global for now. I’ll do some more testing…
But at the other hand, I don’t name things with 4 letter names! They are very clear, such as getSerialKey, encodeSerialKey.
Pretty descriptive!

Well. If you say Private, I’ll do some testing to see what may be the best.
Like any other programmer, I’m a lazy dude…! :slight_smile:

Thanks for great advise!

[quote=155375:@Jakob Krabbe]I’ll stick with Global for now. I’ll do some more testing…
But at the other hand, I don’t name things with 4 letter names! They are very clear, such as getSerialKey, encodeSerialKey.
Pretty descriptive![/quote]

It is indeed a very good habit to use descriptive names. Especially years later when you do not remember very well which is which.

Using Private is a way to prevent errors in case you have the same method name locally and systemwide. But if you have only one method called for instance “getSerialKey”, Global is probably OK.

If you like training videos, we have over 200 videos (currently about 62 hours) of Xojo and Real Studio video available to subscribers at http://xojo.bkeeney.com/XojoTraining/. We have three start-to-finish projects and most of those 200 videos come with a project file with source you can use in your own projects. We even have about 5 hours of iOS specific video.

We talk about project organization, naming conventions, and do a lot of coding. I also don’t edit out the mistakes (I may shorten them tho) because I’ve found that new developers often have a hard time understanding the debugging process.

Thank you Bob! I’ll consider these trainings!


I went Private, to test:
“This method is protected. It can only be called from within its class.”

key.getSerialKey

Global will save me the headache… Until I get better flow with the hacking!

You might also try Protected. In this case you would need to use ModuleName.MethodName.