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.
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
[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.
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.
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.