vbMonday --- any xojo alternative?

Hi,
Anyone know how to convert (FirstDayOfMonth, vbMonday) into xojo coding?
FirstDayOfMonth = (CurDate - (CurDate.Day) + 1)
how to convert “vbMonday”?

Thank you

If all you are after is the first day of the month, then vbMonday is not relevant. In VB, vbMonday is only needed when you care about week numbers, or the day number within a week. That is, does a week start on Monday (like most of the world) or Sunday (like most USA calendars)? The difference can impact which week of the year (1-53) a given date falls, or the day index within a week. Neither applies to simply wanting to know the date of the first of the month.

So the short answer is you do not need to convert vbMonday at all. Example code to get the first day of the month:

Using Xojo.Core
Dim dtNow as Date = Date.Now
Dim FirstOfMonth as New Date(dtNow.Year, dtNow.Month, 1, TimeZone.Current)

It could also be done with the classic framework Date object but I’d suggest you learn and get used to the new Xojo.Core framework as you can use it everywhere (such as in iOS projects).

FirstDayOfMonth
Name of the day (Month 1) ?

If this what you want, in the Classic Framework, you only have to set a date with your Month / Year and set the day to 1.
Then, just use (http://documentation.xojo.com/index.php/Date) DayOfWeek and determine from 0-6 which one it is (Sunday-Saturday).

Easy task.

Thank you very much Douglas,
The lunar calendar program’s data do require that I know if the week start on a Monday.
How would that change the code that you shown me?

Thank you very much.

Thank you very much Emile,
I was using DayOfWeek but not sure how to convert the vbMonday function.

Thank you very much

vbMonday tells the date functions that Monday is the first day of the week.

The first day of the month is always the 1st, even if it is not a Monday

Do you want the date of the first Monday of the month?
If so, get the date which is the 1st, and see if the DayOfWeek value is 1
If so, it was a Monday.
If not, add (7- DayOfWeek) days to the date. (thats a quick guess… do test it)

Thank you very much Jeff, I’ll give it a test.

[quote=352084:@Benny Lee] The lunar calendar program’s data do require that I know if the week start on a Monday.
How would that change the code that you shown me?[/quote]

The code to determine the first day of the month really won’t change depending on what you consider the first day of the week. So I think you probably are looking to know something different than the first day of the month.

If you can describe better exactly what you are looking for, we can give you a better explanation.

Are you looking for what day of the week the month started on? If so, start with the code I gave above then use the DayOfWeek function to determine its day. Note that Sunday = 1, and Monday = 2, etc.

(Aside to Jeff: I had to look it up myself to be sure…)

The original VB code is as follow:

Public Function CheckFloatingFestival(CurDate As Date) As String
'Get festivals has floating date in Solar Calendar
Dim loop1 As Integer
Dim FesMonth As Integer, FesWeek As Integer, FesWeekDay As Integer, FesDay As Integer
Dim SMonth As Integer, SDay As Integer
Dim FirstDayOfMonth As Date

SMonth = Month(CurDate)
SDay = Day(CurDate)
FirstDayOfMonth = CurDate - Day(CurDate) + 1
CheckFloatingFestival = ""
For loop1 = 0 To UBound(FloatingFestival)
    FesMonth = Val(Left(FloatingFestival(loop1), 2))
    If FesMonth = SMonth Then
        FesWeek = Val(Mid(FloatingFestival(loop1), 3, 1))
        FesWeekDay = Val(Mid(FloatingFestival(loop1), 4, 1))
        If FesWeekDay = 0 Then FesWeekDay = 7
        If FesWeekDay < Weekday(FirstDayOfMonth, vbMonday) Then FesWeek = FesWeek + 1
        FesDay = (FesWeek - 1) * 7 + FesWeekDay - Weekday(FirstDayOfMonth, vbMonday) + 1
        If FesDay = SDay Then
            CheckFloatingFestival = Mid(FloatingFestival(loop1), 6)
            Exit For
        End If
    End If
Next

End Function

It is checking against the following :

'1st and 2nd character store month, 3rd store weeks number, 4th store weekday.
FloatingFestival = Array(“0520 Mother’s Day”, _
“1021 Columbus Day”, _
“1144 Thanksgiving Day”)

[quote=352421:@Benny Lee]vbMonday[/quote] definition is here:
https://msdn.microsoft.com/fr-fr/library/microsoft.visualbasic.constants.vbmonday(v=vs.110).aspx

Benny: the Date class entry in the LR is here
http://developer.xojo.com/date

Look at DayOfWeek and WeekOfYear.

The vbMonday function does not exists in Xojo. You have to make the maths by yourself.

BTW: in your Function above, where do you Return the computed String ?

vbMonday is a constant handed over to functions like Weekday(…).

FirstDayOfMonth = CurDate - Day(CurDate) + 1

in Xojo:

FirstDayOfMonth = new date FirstDayOfMonth.Day = 1

[quote]If FesWeekDay = 0 Then FesWeekDay = 7
If FesWeekDay < Weekday(FirstDayOfMonth, vbMonday) Then FesWeek = FesWeek + 1[/quote]

This is adjusting for cases where the dates fall on a weekend.
But the code is pretty obscure …