Overload issue

I am trying to create a series of overloaded methods that all take the same parameters EXCEPT the one is a different datatype in each method…
This is working fine for all but this

Public Sub AddProperty(Name As String,defaultValue As String,readonly As Boolean=False)
 ..... code ....
End Sub

Public Sub AddProperty(Name As String,defaultValue As String(),readonly As Boolean=False)
 .... code....
End Sub

The first passes a scalar string, while the second passes an ARRAY

If I do NOT add the ARRAY version, its fine
but when I do I get TWO errors

  1. the first is tagged as “DUPLICATE METHOD DEFINATION”
  2. the second is marked as “SYNTAX ERROR”

The “duplicate” I would understand if the signatures were the same… but I would have thought the () would have been ok
And I fail to see the syntax error in the second

defaultValue As String()? Don’t you mean defaultValue() As String?

You may be interested in ParamArray: http://documentation.xojo.com/index.php?title=ParamArray&oldid=41227
I think then you wouldn’t need to overload.

Edit: Also, your syntax error - arsDefault() as String not arsDefault as String()

Edit - Looks like Eil beat me to it.

[quote]Dave - Looks like you’re making a mistake I make all the time. Parens are in the wrong place for the String array property.

[code]Public Sub AddProperty(Name As String,defaultValue As String,readonly As Boolean=False)
… code …
End Sub

Public Sub AddProperty(Name As String,defaultValue() As String,readonly As Boolean=False)
… code…
End Sub[/code]

They go after the property name, not after the type. So “defaultValue() as string” instead of “defaultValue as String()”.

HTH,
Anthony[/quote]

This works:

[code]Sub AddProperty(name As String, defaultValue As String, Optional readonly As Boolean = False)

End Sub

Sub AddProperty(name As String, defaultValue() As String, Optional readonly As Boolean = False)

End Sub[/code]

[quote=356851:@Eli Ott]readonly? Don’t you mean Optional?
defaultValue As String()? Don’t you mean defaultValue() As String?[/quote]

Edit: Also, your syntax error - arsDefault() as String not arsDefault as String()[/quote]
Not sure how that is any different… since you need to specifiy the datatype of the param array.
and I have an overload for DOUBLE, STRING, BOOLEAN, FOLDERPATH etc… etc… and only one that passes an Array

With the ParamArray the number of values passed can be variable. I believe it would have to be the last paramter for the method, but you would no longer need to have overloaded methods.

AddProperty("Prop Name", false, "Default Value")

and

AddProperty("Prop Name", false, "Default Value 1", "Default Value 2", "Default Value 3")

could both run the same code for single string values or string arrays.

I wasn’t aware you were overloading with other data types though. Do as you see best fit for the use!

Ok… I see where you were coming from…
for what I am doing that wouldn’t work…
I have to handle a scalar string differently that an array

and yes a Ubound=0 would not be the same

Confused… or did I find a bug?

sub add(name as string, index as integer)
sub add(name as string,index as integer, paramarray list() as string)

these signatures ARE DIFFERENT, it does compile without error
but at runtime

[code]
add(“fred”,14)
add(“barney”,3,“a”,“b”,“c”)

[code]
BOTH call the paramarray version

The first is to “insert an INTEGER called ‘FRED’ with a value of 14”
the second is to “insert a String Array [“a”,“b”,“c”] called “BARNEY” with a current index of 3”

there are other versions of ADD where the 2nd value is BOOLEAN, COLOR, DOUBLE etc…

but this is the only one where the first TWO parameters are the same datatype
and I thought overloads were based on the ENTIRE signature not being the same

Confused…? Because your code will not compile…

Compiler error on the line Add(“Fred”, 14):

This will work:

Sub Add(name As String, index As Integer) Sub Add(name As String, index As Integer, list() As String)
and this:

Sub Add(name As String, index As Integer) Sub Add(name As String, index As Integer, list0 As String, ParamArray list() As String)

my bad… turns out I had an overload calling another overload (which while legal, in this case it DID the wrong thing)

Thanks.