I hate dates!

Ok, so forgive my frustration(s), but I always seem to struggle with dates?

Inside the ‘ValueChanged’ event of a DatePicker plugin

This Code:

Using Xojo.Core

Dim thisDisp As String
Dim thisDayNo As Integer

Dim d As New Date(me.Year, me.Month, me.Day, 0, 0, 0, TimeZone.Current)
Dim di As New DateInterval

di.Days = 1

Dim nd As Xojo.Core.Date = d + di

This Error:

DashWindow.DashDatePck.ValueChanged, line 39 - There is more than one item with this name and it’s not clear to which this refers.
dim nd as new date = d + di

Any help/suggestions greatly appreciated. :wink:

personally I’ve had a few very nice dates… one ended up being my wife of over 38 years :slight_smile:

but I digress :slight_smile:

perhaps (and I don’t know for sure, since I avoid the new framework like the plague)… but since you are
using “USING Xojo.Core” that the “NEW DATE” is confused as to which framework (new or old) it should use?

or D is an old framework date… and you cannot assign it to a new framework date?

(and people ask why I hate the “new framework”… )

I don’t know enough about the ‘new’ framework to have an opinion either way, but I just figure I should go with the latest/greatest?

Anyway … I’m still confused about the error message? I’m guessing I haven’t supplied enough (parameter?) information for the framework to know which Date method to use? …

well I just tried you snippet (I was curious)… and well … for me it worked… or at least compiled and ran
the only thing I changed was the ME.YEAR,ME.MONTH and ME.DAY since I didn’t know who/what “me” was in your context

but normally that msg means the compiler found two or more possible references and didn’t know which one to use…

When you see this:
“There is more than one item with this name and it’s not clear to which this refers…”
it often means that the item appears to be an array, and you haven’t specified an index.

Interesting … so I just changed all the me. references to fixed values:

'Dim d As New Date(me.Year, me.Month, me.Day, 0, 0, 0, TimeZone.Current)
Dim d As New Date(2017, 1, 1, 0, 0, 0, TimeZone.Current)

with no change to the error message?

So very confused???

this is exactly what I ran [macOS 10.11.6/Xojo2016r4.1]

Using Xojo.Core

Dim thisDisp As String
Dim thisDayNo As Integer

Dim d As New Date(2017, 01, 25, 0, 0, 0, TimeZone.Current)
Dim di As New DateInterval

di.Days = 1

Dim nd As Xojo.Core.Date = d + di

Thanks for you efforts Dave, much appreciated.

I’ve copied the code into a new method for testing and still get the same error.

Is there some IDE setting I’m missing maybe?

has nothing to do with IDE settings
have you got other variables name d or di that are local or global in scope ?
something has the compiler very confused

what version are you using ?
and what kind of project ? desktop? iOS? console ? web ?

Version 2017 Release 1.1 and no GLOBALS that I’m aware of that could be conflicting?

My code now looks like this:

Using Xojo.Core

Dim thisDayNo As Integer

Dim d As new Date(me.Year, me.Month, me.Day, 0, 0, 0, TimeZone.Current)
Dim di As New DateInterval

thisDayNo = Me.DateValue.DayOfWeek

Select Case thisDayNo

Case 1 ’ Sunday

Case 2 ’ Monday

di.Days = 1
Dim dTue As Date = d + di
di.Days = 2
Dim dWed As Date = d + di
di.Days = 3
Dim dThu As Date = d + di
di.Days = 4
Dim dFri As Date = d + di
di.Days = 5
Dim dSat As Date = d + di
di.Days = 6
Dim dSun As Date = d + di

MondayDateLbl.Text = Me.DateValue.ShortDate
TuesdayDateLbl.Text = dTue.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
WednesdayDateLbl.Text = dWed.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
ThursdayDateLbl.Text = dThu.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
FridayDateLbl.Text = dFri.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
SaturdayDateLbl.Text = dSat.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)
SundayDateLbl.Text = dSun.ToText(Locale.Current, Date.FormatStyles.Short, Date.FormatStyles.None)

seems to be behaving as I expect, so I’m not really sure why it’s working now?

Sorry for the fuss … moving on now. :wink:

oh, and Desktop project for Windows.

[quote]When you see this:
“There is more than one item with this name and it’s not clear to which this refers…”
it often means that the item appears to be an array, and you haven’t specified an index.[/quote]

Actually no. It just means there is something wrong with the parameters and the Xojo compiler can’t make sense of it. This error message is sometimes just plain wrong. See <https://xojo.com/issue/41473>

Ah the joy of things that autoconvert themselves to other types :slight_smile:
The compiler doesn’t look for JUST perfect matches - it looks for any possible matches even if there are conversions required.
That message comes from cases where there is no perfect match and each of the other candidates requires some number of conversions to make it the correct candidate.
And after this consideration there’s still more than one possible match - hence its ambiguous.

Something like this illustrates

Class Class1
   Sub Constructor(s as string)
End Class

dim v as variant = 123
dim c as new Class1(v)

IF we applied the “there’s no perfect match” there would be a lot of code like this that I’m sure would suddenly have tons of “errors”