none
Insert line RRS feed

  • Question

  • Heya,

    Please, can you help me.

    How I have to us this loop to insert 1 line after each 7 iterations:
    # loop for the header
    for ($Xhea = 1; $Xhea -lt $Xcount;$Xcount++)
    {
    while (($Xhea % 7) -eq ($Xnum -eq $Xcount))
    {
    # table header
    $Xheader      
    continue;
    $Xnum
    }
    }

    Many thanks for your help
    My best regards
    Arnold

    ====================

    ..............
    # head
    $Xheader = "<tr><td>Lnr</td><th>City's</th><th>............</th></tr>"

    # row counter
    $Xname = (1..1)
    $Xlnr = 0

    $Xc_Day = get-date -f "dddd"

    $XtableHead = "<table>"
    $XtableBot = "</table>"

    $Xcount = ($Xreconnect.reconnect.city | ? {$_.name -and $_.$Xc_Day -gt 0}).count

        $XtableHead
        $Xheader
              foreach ($Xuser in ($Xreconnect.reconnect.city | ? {$_.name -and $_.$Xc_Day -gt 0} | sort {$_.name} -Uni ))
                {
                    # row
        $Xnum = $Xname | foreach {'{1}.' -f $Xname[$Xlnr++],$Xlnr}
        
        # items
        "<tr><th><strong>"+'{0:# ### ###}' -f $Xnum +"</strong></th>"
                    "<td><strong>"+((get-culture).TextInfo.ToTitleCase($Xuser.name))+"</strong></td>"
                    "<td>"+$Xuser.av+"</td>"
                    "<td>"+$Xuser.$Xc_Day+"</td></tr>"
        
          # loop for the header
          for ($Xhea = 1; $Xhea -lt $Xcount;$Xcount++)
           {
                    while (($Xhea % 7) -eq ($Xnum -eq $Xcount))
                     {
              # table header
              $Xheader      
                 continue;
              $Xnum
                     }
           }
       }
    $XtableBot

    <#
    the result now is:

    <table>
    <tr><td>Lnr</td><th>City's</th><th>............</th></tr>
    <tr><tr><th><strong>1.</strong></th>
    <td><strong>335Xi</strong></td>
    <td>BAO</td>


    but my idee is this:

    <table>
    <tr><td>Lnr</td><th>City's</th><th>............</th></tr>
    <tr><tr><th><strong>1.</strong></th>
    <td><strong>335Xi</strong></td>
    <td>BAO</td>
    <td>7300190</td></tr>
    <tr><tr><th><strong>2.</strong></th>
    <td><strong>3Dcity</strong></td>
    <td>B-EX</td>
    <td>7493948</td></tr>
    <tr><tr><th><strong>3.</strong></th>
    <td><strong>Ady-Land</strong></td>
    <td>BAO</td>
    <td>19620497</td></tr>
    <tr><tr><th><strong>4.</strong></th>
    <td><strong>Arcade-3000-Fr</strong></td>
    <td>B-EX</td>
    <td>15798641</td></tr>
    <tr><tr><th><strong>5.</strong></th>
    <td><strong>Athome</strong></td>
    <td>BAO</td>
    <td>14176599</td></tr>
    <tr><tr><th><strong>6.</strong></th>
    <td><strong>Bangor</strong></td>
    <td>BAO</td>
    <td>31669714</td></tr>
    <tr><tr><th><strong>7.</strong></th>
    <td><strong>Bangor-Down</strong></td>
    <td>EXT</td>
    <td>1555935</td></tr>
    ????? <tr><td>Lnr</td><th>City's</th><th>............</th></tr>
    ........

    #>

    Thursday, February 13, 2014 10:44 AM

Answers

  • My earlier code was just an example of the basic loop structure.  I didn't mean that you should use the range notation in your code (since you already have an array).  I'm not sure exactly what's going on with all of your code, but try this, as a starting point:

    $Xheader = "<tr><td>Lnr</td><th>City's</th><th>............</th></tr>"
    
    $Xc_Day = get-date -f "dddd"
    
    $XtableHead = "<table>"
    $XtableBot = "</table>"
    
    $array = @(
        $Xreconnect.reconnect.city |
        Where-Object { $_.name -and $_.$Xc_Day -gt 0 } |
        Sort-Object -Property 'Name' -Unique
    )
    
    $XtableHead
    
    for ($i = 0; $i -lt $array.Count; $i++)
    {
        if ($i % 7 -eq 0)
        {
            $Xheader
        }
    
        $Xuser = $array[$i]
    
        $name = (get-culture).TextInfo.ToTitleCase($Xuser.name)
    
        "<tr><th><strong>{0:# ### ###}</strong></th>" -f ($i + 1)
        "<td><strong>$name</strong></td>"
        "<td>$($Xuser.av)</td>"
        "<td>$($Xuser.$Xc_Day)</td></tr>"
    }
    
    $XtableBot


    Thursday, February 13, 2014 5:49 PM

All replies

  • There's a lot of confusing (and probably buggy) things going on with your code, so it's going to take some more work to get this functioning.  However, focusing on just your specific question for now, here's how I would inject a header into every 7 lines of a string array:

    $strings = 1..50
    $header = "Header"
    
    for ($i = 0; $i -lt $strings.Count; $i++)
    {
        if ($i % 7 -eq 0)
        {
            $header
        }
        
        $strings[$i]
    }
    

    Thursday, February 13, 2014 3:13 PM
  • Hello Sir,
    
    Many thanks for you reply!
    Your nested loop works perfect on stand alone!
    
    But inside the script I get now each item 7 times!(repeti.)
    Do you have en little tricky to solve this problem?
    
    great's,
    
    Arnold
    
    =====================
    
    
    # head
    $Xheader = "<tr><td>Lnr</td><th>City's</th><th>............</th></tr>"
    
    # row counter
    $Xname = (1..1)
    $Xlnr = 0
    
    $Xc_Day = get-date -f "dddd"
    
    $XtableHead = "<table>"
    $XtableBot = "</table>"
    
    $Xcount = ($Xreconnect.reconnect.city | ? {$_.name -and $_.$Xc_Day -gt 0}).count
    
    #  =====>  YOUR STUFF
    $Xstrings = 1..$Xcount 
    
    		  $XtableHead
    		  $Xheader
              foreach ($Xuser in ($Xreconnect.reconnect.city | ? {$_.name -and $_.$Xc_Day -gt 0} | sort {$_.name} -Uni ))
                {
    			
    		  #  <=====>  YOUR STUFF	
    		  # loop for the header
    		  for ($Xi = 0; $Xi -lt $Xstrings.Count; $Xi++) 
    		  {     
    		  if ($Xi % 7 -eq 0)     
    		 	 	{         
    		  # <=============>
    		  
    				# row
    				$Xnum = $Xname | foreach {'{1}.' -f $Xname[$Xlnr++],$Xlnr}
    				
    				# This is the probleme now !!!!!!!
    				# items
    				"<tr><th><strong>"+'{0:# ### ###}' -f $Xnum +"</strong></th>"
                    "<td><strong>"+((get-culture).TextInfo.ToTitleCase($Xuser.name))+"</strong></td>"
                    "<td>"+$Xuser.av+"</td>"
                    "<td>"+$Xuser.$Xc_Day+"</td></tr>"
    				}
    			}
    			$Xheader     
    			$Xstrings[$Xi] 
    			}
    $XtableBot

    Thursday, February 13, 2014 5:33 PM
  • My earlier code was just an example of the basic loop structure.  I didn't mean that you should use the range notation in your code (since you already have an array).  I'm not sure exactly what's going on with all of your code, but try this, as a starting point:

    $Xheader = "<tr><td>Lnr</td><th>City's</th><th>............</th></tr>"
    
    $Xc_Day = get-date -f "dddd"
    
    $XtableHead = "<table>"
    $XtableBot = "</table>"
    
    $array = @(
        $Xreconnect.reconnect.city |
        Where-Object { $_.name -and $_.$Xc_Day -gt 0 } |
        Sort-Object -Property 'Name' -Unique
    )
    
    $XtableHead
    
    for ($i = 0; $i -lt $array.Count; $i++)
    {
        if ($i % 7 -eq 0)
        {
            $Xheader
        }
    
        $Xuser = $array[$i]
    
        $name = (get-culture).TextInfo.ToTitleCase($Xuser.name)
    
        "<tr><th><strong>{0:# ### ###}</strong></th>" -f ($i + 1)
        "<td><strong>$name</strong></td>"
        "<td>$($Xuser.av)</td>"
        "<td>$($Xuser.$Xc_Day)</td></tr>"
    }
    
    $XtableBot


    Thursday, February 13, 2014 5:49 PM
  • Hi Sir, Many Thanks for your reply! I can't stop to look your stuff! Great fool for you help. My best regards, Arnold
    Thursday, February 13, 2014 7:48 PM