printf
printf

Reputation: 110

Convert Array to DayOfWeek

any idea how to make function convertArrayToDayOfWeek. I using this dll https://taskscheduler.codeplex.com/documentation

Import System.Win32.TaskScheduler

...

Function convertArrayToDayOfWeek() as DayOfWeek
    Dim a() as integer = {1,2,3,4,5,6}
    Dim d as DayOfWeek

    'todo : how to change a() to something like this
    d = 1 or 2 or 3 or 4 or 5 or 6

    return d
End Function

I try to create a task that will trigger every Monday and Saturday (or any other day depending on the user wishes)

Imports Microsoft.Win32.TaskScheduler

Module Module1

    Sub Main()
        Using ts As New TaskService()
            ' Create a new task definition and assign properties
            Dim td As TaskDefinition = ts.NewTask
            td.RegistrationInfo.Description = "Does something"

            ' Add a trigger that will, starting tomorrow, fire every other week on Monday
            ' and Saturday and repeat every 10 minutes for the following 11 hours
            Dim wt As New WeeklyTrigger()
            wt.StartBoundary = DateTime.Today.AddDays(1)

            '--------------------- need to change the value part at runtime
            wt.DaysOfWeek = DaysOfTheWeek.Monday Or DaysOfTheWeek.Saturday  '<--- hardcoded 
            '--------------------

            wt.WeeksInterval = 2
            wt.Repetition.Duration = TimeSpan.FromHours(11)
            wt.Repetition.Interval = TimeSpan.FromMinutes(10)
            td.Triggers.Add(wt)

            ' Add an action (shorthand) that runs Notepad
            td.Actions.Add(New ExecAction("notepad.exe", "c:\test.log"))

            ' Register the task in the root folder
            ts.RootFolder.RegisterTaskDefinition("Test", td)
        End Using
    End Sub

End Module

look at

wt.DaysOfWeek = DaysOfTheWeek.Monday Or DaysOfTheWeek.Saturday

how to change that value at runtime. I like to use something like this :

wt.DaysOfWeek = convertArrayToDayOfWeek({1,6}) 'the results of this function should 'DaysOfTheWeek.Monday Or DaysOfTheWeek.Saturday' 

Upvotes: 0

Views: 484

Answers (1)

printf
printf

Reputation: 110

DaysOfWeek is DaysOfTheWeek Enum

Function convertArrayToDayOfWeek(a() as integer) as DayOfTheWeek 'change DayOfWeek to DayOfTheWeek
    'Dim a() as integer = {1,2,3,4,5,6} 'receive value from outside
    Dim d as DayOfTheWeek 'change DayOfWeek to DayOfTheWeek

    for each i as integer in a
        Select Case i
            Case 1 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Monday
            Case 2 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Tuesday
            Case 3 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Wednesday
            Case 4 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Thursday
            Case 5 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Friday
            Case 6 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Saturday
            Case 7 : d += Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Sunday
        End Select   
    next

    return d
End Function

Upvotes: 1

Related Questions