Day switch

This topic contains 2 replies, has 2 voices, and was last updated by  Arnold 1 week, 5 days ago.

  • Author
    Posts
  • #81175

    Arnold
    Participant

    Hello

    please, i need en switch statement
    i have to present every day one text (loop):

    1. day english text
    2. day french text
    3. day german text

    i have us:
    (get-date).DayOfYear | % {if($_ % 2 -eq 1 ) {...}
    and
    (get-date).DayOfYear | % {if($_ % 2 -eq 0 ) {...}

    how i have to do with the 3. day?

    Thx for your help
    Arnold

  • #81205

    postanote
    Participant

    I am not real sure what you end goals are, but if these are the only 3 items you are looking to use, a switch is possible.
    Yet, with such a small list you could do this with the multiple if statement track you are on now.

    Something like ...

    # Using nested 'If' statement

    1..3 | % { $_
    If( $_ -eq 1 )
    {'Day English Text'}
    ElseIf ($_ -eq 2 )
    {'Day French Text'}
    Else
    { 'Day German Text' }
    }

    # Results

    1
    Day English Text
    2
    Day French Text
    3
    Day German Text

    I am also not sure of the selection of DayOfYear and a result for just 3 options, since there are 365 options for a year array, with of course DayOfWeek being 7. But we all know those are obvious things, but just I just saying, I don't get it.

    But for what you ask for, you just need to open the PowerShell ISE and in a new script pane,
    Select the Edit Menu item,
    Select Start Snippits
    Scroll to find the 'switch' snippet and double click that...

    switch ($x)
    {
    'value1' {}
    {$_ -in 'A','B','C'} {}
    'value3' {}
    Default {}
    }

    ... then alter to fit you needs.

    # Altered for the DayOfValue

    $DayValue = Read-Host 'Enter a Day Value as 1, 2 or 3'

    switch ($DayValue)
    {
    1 { 'Day English text' }
    2 { 'Day French text' }
    3 { 'Day German text' }
    Default {"The Day Value could not be determined."}
    }

    # Results

    Enter a Day Value as 1, 2 or 3: 1
    Day English text

  • #81211

    Arnold
    Participant

    Good Morning,

    Tnx for your reply and your help.
    Your solutions are great!

    Arnold

    Nota bene:
    The solution

You must be logged in to reply to this topic.