From what I’m reading in the archives, it seems that you can’t use functions and subroutines the same way as in all other programming languages. For instance, at the bottom of your code, you put a function or subroutine which you call in the main part of your code. I’m trying to use the following subroutine but I’m getting a syntax error. So am I correct in concluding that Xojo constrains you to using methods? Thanks!
Sub checkValues()
Select Case Sharp.VisualState
Case CheckBox.VisualStates.Checked
theNote = theNote + "#"
Sharp.VisualState = CheckBox.VisualStates.Unchecked
End
End Sub
Well, I don’t know about all other programming languages, but each function and each subroutine is to be declared separately. You can’t nest a function (say) inside another.
Since XoJo methods can either be something you just call, call and send data or call send and/or receive data, it would seem to me that all the bases are covered. You just aren’t declaring what it is like your example above.
Yes, all the bases are covered except that you’re always required to go outside of the code you’re working on when you need to update your method. As I was saying to Tim, I can’t speak to every language out there but the ones I’ve used which is at least 9, all allow you to write your functions in the same file as your main code. This to me is a very convenient way of working but to each their own. Anyways, I guess my question has been answered; methods are the only game in town. Thanks for your reply!
Bottom line is that Xojo is not that different compared to other languages. The Xojo IDE IS different. Lets compare with .Net, where you have to type everything by hand. In Xojo, for example, when you add a method, in the code editor you don’t need to type
function foo (arg1 as X, arg2 as Y) return Z
End function
In the code editor all you need to supply is the code between function and End function. The args are specified in the Inspector, the same is true for the type of return value if any.
But if you print foo then you will see that Xojo automatically create the beginning and ending line. On top of that when you need to implement interfaces, all you have to do is select them in a list, and Xojo will create the empty methods ready for you too fill.
In Xojo, you need to type only the essential part, and the code is nicely displayed in the left pane !
This is one of the things I really love about Xojo - methods and functions are forced to be self-contained and separate. I dabbled with Swift for a time some years ago and what a mess of spaghetti code it is capable of, nay encourages, generating.
for a better overview its better to see all methods at once and fly over from top to bottom.
as example you unfold only parts where you work.
i like to have two ways of editing.
copy one method to a other place is inconvenient.
And I wish the Inspector would stay hidden after I’ve hidden it. And I wish the Navigator would stay in the state in which I leave it. Nothing worse than software that thinks it’s smart.
Copy-and-paste is one of the most annoying features of Xojo.
Does the navigator have to be blue or grey when copying controls? I can’t remember. Even worse, when copying multiple controls the color usually is the wrong one. Then I have to select the controls again.
Copy a method, make a new class, paste the method, nothing. Insert a blank method, paste again, delete the blank method.
For some elements I have to select the parent like “Methods” or another sibling for pasting. Why? The clipboard should contain enough information for pasting.
AS you likely know grey mans that the navigator does not have the focus and this why you don’t get the results one would expect…
That said in the IDE the focus is often NOT where I expect to be and that causes me issues… but I have just learned to live with it…
RealStudio was much more user friendly and efficient IDE IMO, even if it did not look “modern” enough.
There were a LOT of criticisms of the Navigator and other aspects of the IDE design when it was initially in beta testing … but by then it was too late.
Over the intervening years, some of the issues have been improved, but from a usage standpoint, it is still IMO inferior to what came before (and before that!)
But I will reserve judgment on the results until I see if they actually fix the issues with the current IDE without creating other equally or more annoying issues.
Because I never want to code the same piece of logic in multiple places, I’ve occasionally wanted to have a very small reusable subroutine to do something at multiple places within that same method. The subroutine’s scope should be that the method and NOT have a private scope to itself, and no parameters in or out either. In fact you might think of it more as a code macro to be referenced at multiple points in the method rather than any kind of function or method call. Sort of a piece of “method local” reusable code.
I’ve not wanted that very often though… generally scoped functions are the preferred approach.