Method Parameters - My new favorite coding thing.

I just started using method parameters and with them, you can do just about anything, without having to create a single property. Before using parameters, I used to use properties.

Needless to say, I now love using parameters. However one thing I despise is when you create a method, after naming it and pressing the ‘tab’ key, the cursor automatically moves to the code editor, and doesn’t stay in the “Parameters” field.

This is one of many bugs that has been reported for the “new” IDE

Hi Shane,

I have no idea what method parameters are, would you mind giving an example or pointing me to some explanation? You made me curious.

I have tried the language reference and the user guide but couldn’t find anything on this topic.

Thanks,

Julen

Please sign on to the feedback report for this behavior. This is one of my chief annoyances in the IDE

[quote=77398:@Julen Ibarretxe Uriguen]Hi Shane,

I have no idea what method parameters are, would you mind giving an example or pointing me to some explanation? You made me curious.

I have tried the language reference and the user guide but couldn’t find anything on this topic.

Thanks,

Julen[/quote]

When you create a method, the first text box in the inspector is the method name. The second text box is where the method parameters go.

Ex: Name As String will enable you to use the “Name” string in the method.

PushButton.Action:

  Dim SzsTool As New SZSManager
  SzsTool.PatchSpeed(UniversalFileName.Text, SpeedModField.Text.Val) //Method to execute followed by Method Parameters.
  SolarLogOutputArea.Text = SzsTool.TheOutput
Sub PatchSpeed (FileName As String, Speed As Integer)
  Dim PatchSpeed As New Shell
  PatchSpeed.Execute(ToolCommand, "patch" + " " + FileName + " " + "--speed-mod" + " " + Str(Speed))
  TheOutput = PatchSpeed.ReadAll
  MsgBox "Transformation Complete!"
End Sub

Added information to this feedback case:
<https://xojo.com/issue/20953>

Thanks for the reply. I didn’t understand you meant those method parameters… how where you doing it before, by using global/public properties only?

I will add my points to that feedback case.

Julen

I guess you mean on Mac OS X. On Windows, It stays in the parameters field if you press [ENTER] then [TAB] after having entered the Method name.

Cheers,
Guy.

[quote=77454:@Julen Ibarretxe Uriguen]Thanks for the reply. I didn’t understand you meant those method parameters… how where you doing it before, by using global/public properties only?

I will add my points to that feedback case.

Julen[/quote]

Basically, I’ve been using properties which is a bad practice (IMO) when they’re only going to get used in one method. Properties are great for multi-method usage.

[quote=77459:@Guy Rabiller]I guess you mean on Mac OS X. On Windows, It stays in the parameters field if you press [ENTER] then [TAB] after having entered the Method name.

Cheers,
Guy.[/quote]

Thanks for the info. Yet another OS X glitch.

If I understand you correctly, you were setting property values, then running methods that expected to find values in those properties. Now you are passing those values in parameters if there is a single method, but using properties if you need to call multiple methods on the same values, yes?

My advice: If you don’t need to keep values around, always using parameters even if it will end up being processed by multiple methods. Parameters are always passed by reference, so there really isn’t a downside. Use ByRef if you need to modify the value of the original variable. Your methods will be much more portable and easier to maintain.

Intrinsic types (e.g. Integer) are by default passed by value.

Using parameters are invaluable when designing reusable code. Just keep in mind that there are times when a property might still be a better fit than a parameter.

Yep. I find that stuff like default text that can be modified is best stored in properties.

Method parameters and properties are different things, both useful, but not to be used as substitutes each one for the other.