问:
Python regex split multiple matches
I'm trying to split strings containing sequences of 2 different characters into groups. If we assume the characters are a and b, the plain text rules for grouping are:

groups consist of 0+ a's followed by 1+ b's

all following a's are included in the next group, unless we're at the end of the word.

For example: after processing tests the goal is to break into groups like expected.

```<code>tests = ['abab',
    'ababab',
    'aabab',
    'aababa',
    'aba',
    'baba']

expected = [['ab','ab'],
    ['ab','ab','ab'],
    ['aab','ab'],
    ['aab','aba'],
    ['aba'],
    ['b','aba']]
</code>```

The closest I've gotten is the below:

```<code>import re

# filter() returns iterator not list in Python 3
def testing(s):
    return list(filter(None, re.compile('(a*b+a*(?=$))').split(s)))

output = [testing(s) for s in tests]

output

[['ab', 'ab'], ['abab', 'ab'], ['aab', 'ab'], ['aab', 'aba'], ['aba']]
</code>```

Which does well on groups of 1-2 but not for groups larger than that, which means my regex needs improvement. Should I rethink the approach? I could probably do something brute force with for loops but was hoping for something more elegant.

N.B.: This post leads me to believe that .split() may not be the way to go here, but I've gotten the best results with it so far.

答:
I believe you're on the right track. However, your regex has more bugs than you think. Your test cases do not cover all possible scenarios, and so you don't realise this.

Since you have a couple of special cases, you should treat them separately. For example, the last input is a special case because it matches aba. Similarly, list the others separately and join them with |. You can also use re.findall, it's cleaner.

```<code>tests = ['abab',
        'ababab',
        'aabab',
        'aababa',
        'aba',
        'baba']

def testing(s):
    return re.findall('(?:a*b+a+$)|(?:a*b+)|(?:b+a+)', s)

output = [testing(s) for s in tests]
print(output)
</code>```

Output:

```<code>[['ab', 'ab'], ['ab', 'ab', 'ab'], ['aab', 'ab'], ['aab', 'aba'], ['aba'], ['b', 'aba']]
</code>```

Title: Python regex split multiple matches

Body:
I'm trying to split strings containing sequences of 2 different characters into groups. If we assume the characters are a and b, the plain text rules for grouping are:

groups consist of 0+ a's followed by 1+ b's

all following a's are included in the next group, unless we're at the end of the word.

For example: after processing tests the goal is to break into groups like expected.

tests = ['abab',
    'ababab',
    'aabab',
    'aababa',
    'aba',
    'baba']

expected = [['ab','ab'],
    ['ab','ab','ab'],
    ['aab','ab'],
    ['aab','aba'],
    ['aba'],
    ['b','aba']]

The closest I've gotten is the below:

import re

# filter() returns iterator not list in Python 3
def testing(s):
    return list(filter(None, re.compile('(a*b+a*(?=$))').split(s)))

output = [testing(s) for s in tests]

output

[['ab', 'ab'], ['abab', 'ab'], ['aab', 'ab'], ['aab', 'aba'], ['aba']]

Which does well on groups of 1-2 but not for groups larger than that, which means my regex needs improvement. Should I rethink the approach? I could probably do something brute force with for loops but was hoping for something more elegant.

N.B.: This post leads me to believe that .split() may not be the way to go here, but I've gotten the best results with it so far.

Body:
I believe you're on the right track. However, your regex has more bugs than you think. Your test cases do not cover all possible scenarios, and so you don't realise this.

Since you have a couple of special cases, you should treat them separately. For example, the last input is a special case because it matches aba. Similarly, list the others separately and join them with |. You can also use re.findall, it's cleaner.

tests = ['abab',
        'ababab',
        'aabab',
        'aababa',
        'aba',
        'baba']

def testing(s):
    return re.findall('(?:a*b+a+$)|(?:a*b+)|(?:b+a+)', s)

output = [testing(s) for s in tests]
print(output)

Output:

[['ab', 'ab'], ['ab', 'ab', 'ab'], ['aab', 'ab'], ['aab', 'aba'], ['aba'], ['b', 'aba']]


来源: stackexchange

问:
How to align radio buttons and labels?
I am styling an integration into a 3rd party system, and need to format some radio buttons. The vendor gives us this HTML:

```<code><span class="radiocontainer">
    <label for="genderMale" class="radiolabel">Male</label>
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    <label for="genderFemale" class="radiolabel">Female</label>
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">
</span>
</code>```

and I need it to render it like so:

I tried, and failed, using flexbox to accomplish this:

span.radiocontainer {
  float: none;
  display: flex;
  align-items: left;
  justify-content: left;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: left;
}

span.radiocontainer > label.selected.radiolabel {
  box-shadow: none;
  width: 50%;
  border: 0px;
}

span.radiocontainer > input {
  width: 50%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><span class="radiocontainer">
    <label for="genderMale" class="radiolabel">Male</label>
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    <label for="genderFemale" class="radiolabel">Female</label>
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">
</span></code>```

Is there any way for me to format the radio buttons on the left? Or do I need to change my design?

I cannot change the HTML, as it is from a vendor, CSS is the only thing we get to customize.

答:
You can move inputs to left by hard-coding order for each input and label.

.radiocontainer {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
}
.radiocontainer input,
.radiocontainer label {
  width: 50%;
  margin: 0;
}

input:nth-of-type(1) {order: 1}
input:nth-of-type(2) {order: 3}
label:nth-of-type(1) {order: 2}
label:nth-of-type(2) {order: 4}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><span class="radiocontainer">
    <label for="genderMale" class="radiolabel">Male</label>
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    <label for="genderFemale" class="radiolabel">Female</label>
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">
</span></code>```

ContentLicense: CC BY-SA 3.0

Title: How to align radio buttons and labels?

Body:
I am styling an integration into a 3rd party system, and need to format some radio buttons. The vendor gives us this HTML:

    Male
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    Female
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">

and I need it to render it like so:

I tried, and failed, using flexbox to accomplish this:

span.radiocontainer {
  float: none;
  display: flex;
  align-items: left;
  justify-content: left;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: left;
}

span.radiocontainer > label.selected.radiolabel {
  box-shadow: none;
  width: 50%;
  border: 0px;
}

span.radiocontainer > input {
  width: 50%;
}

    Male
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    Female
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">

Is there any way for me to format the radio buttons on the left? Or do I need to change my design?

I cannot change the HTML, as it is from a vendor, CSS is the only thing we get to customize.

Body:
You can move inputs to left by hard-coding order for each input and label.

.radiocontainer {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
}
.radiocontainer input,
.radiocontainer label {
  width: 50%;
  margin: 0;
}

input:nth-of-type(1) {order: 1}
input:nth-of-type(2) {order: 3}
label:nth-of-type(1) {order: 2}
label:nth-of-type(2) {order: 4}

<span class="radiocontainer">
    <label for="genderMale" class="radiolabel">Male</label>
    <input class="selector" id="genderMale" name="Gender" type="radio" value="2">
    <label for="genderFemale" class="radiolabel">Female</label>
    <input class="selector" id="genderFemale" name="Gender" type="radio" value="1">
</span>


问:
How to put a space in a sphinx url for windows drive
I'm trying to create a hyperlink to a folder that has a space in it.
The space is removed because of the way rst is processing the link.

Unfortunately I can't change the name of the folder because I'm not the owner.

This was solved below by adding %20 but now there is a second problem:

The path should be "file:///T:/my_path/A&B Tools".

It can also be represented as "\\network.com\my_path\A&B Tools".

```<code>* First link   `hyperlink-name-1`_
* Second link  `hyperlink-name-2`_

.. _hyperlink-name-1: file:///T:/my_path/A&B%20Tools
.. _hyperlink-name-2: \\\\network.com\\my_path\\A&B%20Tools
</code>```

The first link works when I map network.com to T:

Edit:

Thanks to Steve I looked at the html I see when I use second link. The windows path starting with \ doesn't seem to work properly. I think this is a windows interpretation of the path.

答:
Thank you Steve for helping me. I needed five slashes  file://///server01/my_path/ as shown here:

What are the ways to make an html link open a folder

Body:
I'm trying to create a hyperlink to a folder that has a space in it.
The space is removed because of the way rst is processing the link.

Unfortunately I can't change the name of the folder because I'm not the owner.

This was solved below by adding %20 but now there is a second problem:

The path should be "file:///T:/my_path/A&B Tools".

It can also be represented as "\\network.com\my_path\A&B Tools".

* First link   `hyperlink-name-1`_
* Second link  `hyperlink-name-2`_

.. _hyperlink-name-1: file:///T:/my_path/A&B%20Tools
.. _hyperlink-name-2: \\\\network.com\\my_path\\A&B%20Tools

The first link works when I map network.com to T:

Edit:

Thanks to Steve I looked at the html I see when I use second link. The windows path starting with \ doesn't seem to work properly. I think this is a windows interpretation of the path.


问:
How to run automated Selenium test with Headless Chrome browser?
All automated test which currently runs on Selenium webdriver, is there any way to run all of them with new Headless chrome?</p>

答:
Yes you can  run all of them with new Headless chrome. You need  to use chrome version 59  and add two chromeOptions to use headless chrome in selenium

Here is the code

https://www.automation99.com/2017/07/how-to-use-chrome-headless-using.html


问:
Nested Flexbox with horizontal overflow
I am using a nested flexbox layout.

I would like a left nav to always be 1/3rd of the page, and the right side always be 2/3rds.

The left nav should always stay in view.

The right side (an image carousel in my case) should always take up 2/3rds and have a horizontal scrollbar on the boxes.

In the code below, it simply stretches and ignores the overflow.

  Top Header (should stay in view)

    LeftNav

```

答:
First, I've moved your styles to classes. Don't use inline CSS.

flex CSS property is shorthand for setting  flex: [flex-grow] [flex-shrink] [flex-basis].

You can set fixed percentage to your flex-basis values and zeros to flex-grow and flex-shrink to avoid flex items growing and shrinking.

Also you show move scroll CSS to your right nav block.

*,
*:before,
*:after {
  box-sizing: border-box;
}

.main-container {
  display: flex;
}

.left-nav {
  flex: 0 0 calc(100% / 3); /* One third width */
}

.right-nav {
  flex: 0 0 calc(200% / 3); /* Two third width */
  overflow-x: scroll;
}

.right-nav-container {
  display: flex;
}

.right-nav-item {
  min-width: 400px;
  height: 500px
}

.right-nav-item:nth-child(1) {
  background-color: blue;
}

.right-nav-item:nth-child(2) {
  background-color: red;
}

.right-nav-item:nth-child(3) {
  background-color: green;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div>
  Top Header (should stay in view)
</div>
<div class="main-container">
  <div class="left-nav">
    LeftNav
  </div>
  <div class="right-nav">
    <div class="right-nav-container">
      <div class="right-nav-item">
      </div>
      <div class="right-nav-item">
      </div>
      <div class="right-nav-item">
      </div>
    </div>
  </div>
</div></code>```

Title: Nested Flexbox with horizontal overflow

Body:
First, I've moved your styles to classes. Don't use inline CSS.

flex CSS property is shorthand for setting  flex: [flex-grow] [flex-shrink] [flex-basis].

You can set fixed percentage to your flex-basis values and zeros to flex-grow and flex-shrink to avoid flex items growing and shrinking.

Also you show move scroll CSS to your right nav block.

*,
*:before,
*:after {
  box-sizing: border-box;
}

.main-container {
  display: flex;
}

.left-nav {
  flex: 0 0 calc(100% / 3); /* One third width */
}

.right-nav {
  flex: 0 0 calc(200% / 3); /* Two third width */
  overflow-x: scroll;
}

.right-nav-container {
  display: flex;
}

.right-nav-item {
  min-width: 400px;
  height: 500px
}

.right-nav-item:nth-child(1) {
  background-color: blue;
}

.right-nav-item:nth-child(2) {
  background-color: red;
}

.right-nav-item:nth-child(3) {
  background-color: green;
}

<div>
  Top Header (should stay in view)
</div>
<div class="main-container">
  <div class="left-nav">
    LeftNav
  </div>
  <div class="right-nav">
    <div class="right-nav-container">
      <div class="right-nav-item">
      </div>
      <div class="right-nav-item">
      </div>
      <div class="right-nav-item">
      </div>
    </div>
  </div>
</div>


问:
Syntax error while running the code
The error is in the lines 431,451,452 and 455.

ERROR:- Line 431. Choice .to. is not a static expression.
 Line 451. Choice + is not a static expression.
 Line 452. Choice + is not a static expression.
 Line 455. Choice time_period_counter is not a static expression.

The code that i have attached is quite long but the logic is quite simple. It is regarding syntax of switch case.

Please help!!

```----------------------------------------------------------------------------------
-- Company: IIST
-- Engineer: Leen Roque Robin
--
-- Create Date:    23:14:17 06/22/2017
-- Design Name:
-- Module Name:    data - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:     To create the corresponding output data as per the command received from the command_interface module
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity data_output is
    Port (  --Input signals
               Por              : in std_logic;
               sys_clk          : in std_logic;
               start_bit        : in std_logic;
               mode_bit1        : in std_logic_vector(2 downto 0);
               mode_bit2        : in std_logic_vector(2 downto 0);
               mode_bit3        : in std_logic_vector(2 downto 0);
               input_data       : in std_logic_vector(7 downto 0);
                card_id         : in std_logic_vector(7 downto 0);

            --Output signals
                clk             : out std_logic;
               pkt_start        : out std_logic;
               dataws           : out std_logic;
               data             : out std_logic_vector(15 downto 0)
--             random_flag      :out std_logic
           );
end data_output;

architecture Behavioral of data_output is
signal count                :   integer:=0;
signal time_period_counter  :   integer:=0;
signal window_counter       :   integer:=0;

constant data_AA55          :   std_logic_vector(15 downto 0):=x"AA55";
constant data_5555          :   std_logic_vector(15 downto 0):=x"5555";

constant word_1             :   std_logic_vector(15 downto 0):=x"F8DD";
constant word_2             :   std_logic_vector(15 downto 0):=x"4259";
signal word_3               :   std_logic_vector(15 downto 0);
constant word_4             :   std_logic_vector(15 downto 0):=x"5231";
signal word_5               :   std_logic_vector(15 downto 0);
signal word_6               :   std_logic_vector(15 downto 0);
signal word_7               :   std_logic_vector(15 downto 0);
signal word_8               :   std_logic_vector(15 downto 0):=x"F8DD";
signal word_9               :   std_logic_vector(15 downto 0):=x"F8DD";
signal word_10              :   std_logic_vector(15 downto 0):=x"F8DD";

constant word_11                :   std_logic_vector(15 downto 0):=x"00AA";
constant word_12                :   std_logic_vector(15 downto 0):=x"00AB";
constant word_13                :   std_logic_vector(15 downto 0):=x"00AC";
constant word_14                :   std_logic_vector(15 downto 0):=x"00AD";
constant word_15                :   std_logic_vector(15 downto 0):=x"00AE";
constant word_16                :   std_logic_vector(15 downto 0):=x"00AF";
constant word_17                :   std_logic_vector(15 downto 0):=x"00BA";
constant word_18                :   std_logic_vector(15 downto 0):=x"00BB";
constant word_19                :   std_logic_vector(15 downto 0):=x"00BC";
constant word_20                :   std_logic_vector(15 downto 0):=x"00BD";
constant word_21                :   std_logic_vector(15 downto 0):=x"00BE";
constant word_22                :   std_logic_vector(15 downto 0):=x"00BF";
constant word_23                :   std_logic_vector(15 downto 0):=x"00CA";
constant word_24                :   std_logic_vector(15 downto 0):=x"00CB";
constant word_25                :   std_logic_vector(15 downto 0):=x"00CC";
constant word_26                :   std_logic_vector(15 downto 0):=x"00CD";
constant word_27                :   std_logic_vector(15 downto 0):=x"00CE";
constant word_28                :   std_logic_vector(15 downto 0):=x"00CF";
constant word_29                :   std_logic_vector(15 downto 0):=x"00DA";
constant word_30                :   std_logic_vector(15 downto 0):=x"00DB";
constant word_31                :   std_logic_vector(15 downto 0):=x"00DC";
constant word_32                :   std_logic_vector(15 downto 0):=x"00DD";
constant word_33                :   std_logic_vector(15 downto 0):=x"00DE";
constant word_34                :   std_logic_vector(15 downto 0):=x"00DF";
constant word_35                :   std_logic_vector(15 downto 0):=x"00EA";
constant word_36                :   std_logic_vector(15 downto 0):=x"00EB";
constant word_37                :   std_logic_vector(15 downto 0):=x"00EC";
constant word_38                :   std_logic_vector(15 downto 0):=x"00ED";
constant word_39                :   std_logic_vector(15 downto 0):=x"00EE";
constant word_40                :   std_logic_vector(15 downto 0):=x"00EF";
constant word_41                :   std_logic_vector(15 downto 0):=x"00FA";
constant word_42                :   std_logic_vector(15 downto 0):=x"00FB";
constant word_43                :   std_logic_vector(15 downto 0):=x"00FC";
constant word_44                :   std_logic_vector(15 downto 0):=x"00FD";
constant word_45                :   std_logic_vector(15 downto 0):=x"00FE";
constant word_46                :   std_logic_vector(15 downto 0):=x"00FF";
constant word_47                :   std_logic_vector(15 downto 0):=x"01AA";
constant word_48                :   std_logic_vector(15 downto 0):=x"01AB";
constant word_49                :   std_logic_vector(15 downto 0):=x"01AC";
constant word_50                :   std_logic_vector(15 downto 0):=x"01AD";
constant word_51                :   std_logic_vector(15 downto 0):=x"01AE";
constant word_52                :   std_logic_vector(15 downto 0):=x"01AF";
constant word_53                :   std_logic_vector(15 downto 0):=x"01BA";
constant word_54                :   std_logic_vector(15 downto 0):=x"01BB";
constant word_55                :   std_logic_vector(15 downto 0):=x"01BC";
constant word_56                :   std_logic_vector(15 downto 0):=x"01BD";
constant word_57                :   std_logic_vector(15 downto 0):=x"01BE";
constant word_58                :   std_logic_vector(15 downto 0):=x"01BF";
constant word_59                :   std_logic_vector(15 downto 0):=x"01CA";
constant word_60                :   std_logic_vector(15 downto 0):=x"01CB";
constant word_61                :   std_logic_vector(15 downto 0):=x"01CC";
constant word_62                :   std_logic_vector(15 downto 0):=x"01CD";
constant word_63                :   std_logic_vector(15 downto 0):=x"01CE";
constant word_64                :   std_logic_vector(15 downto 0):=x"01CF";
constant word_65                :   std_logic_vector(15 downto 0):=x"01DA";
constant word_66                :   std_logic_vector(15 downto 0):=x"01DB";
constant word_67                :   std_logic_vector(15 downto 0):=x"01DC";
constant word_68                :   std_logic_vector(15 downto 0):=x"01DD";
constant word_69                :   std_logic_vector(15 downto 0):=x"01DE";
constant word_70                :   std_logic_vector(15 downto 0):=x"01DF";
constant word_71                :   std_logic_vector(15 downto 0):=x"01EA";
constant word_trailer               :   std_logic_vector(15 downto 0):=x"01FF";

signal word_6_7             :   std_logic_vector(31 downto 0);
signal word_8_9             :   std_logic_vector(31 downto 0);

--prf values
signal prf1_value           :   integer:=10417;
signal prf2_value           :   integer:=11161;
signal prf3_value           :   integer:=5581;
signal prf4_value           :   integer:=11161;
--window values
--window for prf1
signal prf1_width1          :   integer:=2816;
signal prf1_width2          :   integer:=3129;
signal prf1_width3          :   integer:=3441;
signal prf1_width4          :   integer:=3754;

--window for prf2
signal prf2_width1          :   integer:=1563;
signal prf2_width2          :   integer:=2813;
signal prf2_width3          :   integer:=4063;
signal prf2_width4          :   integer:=5313;

--window for prf3
signal prf3_width1          :   integer:=1094;
signal prf3_width2          :   integer:=1719;
signal prf3_width3          :   integer:=2344;
signal prf3_width4          :   integer:=2969;

--window for prf4
signal prf4_width1          :   integer:=1094;
signal prf4_width2          :   integer:=1719;
signal prf4_width3          :   integer:=2344;
signal prf4_width4          :   integer:=2969;

signal sample_data          :   std_logic_vector(15 downto 0);
signal test_sample          :   std_logic_vector(7 downto 0);
signal random_flag          :   std_logic;
signal data_in                  :  std_logic_vector(15 downto 0);
signal counter                  :  std_logic_vector(15 downto 0);

--Random Sequence generation
Component random_data_generator
Port(--Input signals
        por             :   in std_logic;
        sys_clk         :   in std_logic;
        random_flag     :   in std_logic;
        --Output signals
        random_data     :   out std_logic_vector(15 downto 0)

);
end component;

begin

A:  random_data_generator port map (por,sys_clk,random_flag,data_in);

    process(por,sys_clk)
    begin
    if(por='0') then
        time_period_counter     <= 0;
        window_counter          <= 0;

        word_3                      <=  (others=>'0');
        word_5                      <=  (others=>'0');
        word_6_7                        <= (others=>'0');
        word_8_9                        <= (others=>'0');
--      word_6                      <=  (others=>'0');
--      word_7                      <=  (others=>'0');
--      word_8                      <= (others=>'0');
--      word_9                      <=  (others=>'0');
        word_10                     <=  (others=>'0');

    elsif(falling_edge(sys_clk)) then
    --Finding word 3
    case card_id is
        when x"01"  =>  word_3  <=  x"F0F0";
        when x"02"  =>  word_3  <=  x"F00F";
        when x"03"  =>  word_3  <=  x"0FF0";
        when x"04"  =>  word_3  <=  x"0F0F";
        when others => word_3   <= x"0000";
    end case;
    --Finding word 10
    if(mode_bit3 = "011") then
        word_10(10 downto 8)    <=  "111";
    end if;
    if(mode_bit1 = "000") then
        word_10(3 downto 0) <=  "0000";
    elsif(mode_bit1 = "001") then
        word_10(3 downto 0) <=  "0001";
    elsif(mode_bit1 = "010") then
        word_10(3 downto 0) <=  "0010";
    elsif(mode_bit1 = "011") then
        word_10(3 downto 0) <=  "0011";
    end if;

    --Checking PRF
    case mode_bit1 is
        when "000"  =>  time_period_counter <= prf1_value;
            --Checking receive window
            case mode_bit2 is
                when "000"  => window_counter <= prf1_width1;
                when "001"  => window_counter <= prf1_width2;
                when "010"  => window_counter <= prf1_width3;
                when "011"  => window_counter <= prf1_width4;
                when others => window_counter <= prf1_width1;
            end case;

        when "001"  =>  time_period_counter <= prf2_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf2_width1;
                when "001"  => window_counter <= prf2_width2;
                when "010"  => window_counter <= prf2_width3;
                when "011"  => window_counter <= prf2_width4;
                when others => window_counter <= prf2_width1;
            end case;

        when "010"  =>  time_period_counter <= prf3_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf3_width1;
                when "001"  => window_counter <= prf3_width2;
                when "010"  => window_counter <= prf3_width3;
                when "011"  => window_counter <= prf3_width4;
                when others => window_counter <= prf3_width1;
            end case;

        when "011"  =>  time_period_counter <= prf4_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf4_width1;
                when "001"  => window_counter <= prf4_width2;
                when "010"  => window_counter <= prf4_width3;
                when "011"  => window_counter <= prf4_width4;
                when others => window_counter <= prf4_width1;
            end case;
        when others =>  time_period_counter <=  prf1_value;
                        window_counter      <=  0;
        end case;
    end if;

    if(por='0') then
        test_sample     <= (others=>'0');
        sample_data     <= (others=>'0');
        pkt_start       <=  '0';
        dataws          <=  '0';
        count               <=  0;
        counter         <=  x"0000";
    elsif(falling_edge(sys_clk)) then

    if(start_bit='1') then
        count   <=  count+1;
        case count is
            when 1 to 2 =>  pkt_start   <=  '1';
                                dataws      <=  '0';
            when 3  =>  pkt_start   <=  '0';
                            dataws      <=  '0';
            when 4  =>  dataws      <=  '1';
                            word_5      <=  word_5+'1';
                            word_6_7        <=  word_6_7+'1';
                            word_8_9        <=  word_8_9+'1';
                            sample_data <= word_1;
            when 5  =>  dataws      <=  '1';
                            sample_data <= word_2;
            when 6  =>  dataws      <=  '1';
                            sample_data <= word_3;
            when 7  =>  dataws      <=  '1';
                            sample_data <= word_4;
            when 8  =>  dataws      <=  '1';
                            sample_data <= word_5;
            when 9  =>  dataws      <=  '1';
                            sample_data <= word_6_7(31 downto 16);
            when 10 =>  dataws      <=  '1';
                            sample_data <= word_6_7(15 downto 0);
            when 11 =>  dataws      <=  '1';
                            sample_data <= word_8_9(31 downto 16);
            when 12 =>  dataws      <=  '1';
                            sample_data <= word_8_9(15 downto 0);
            when 13 =>  dataws      <=  '1';
                            sample_data <= word_10;
            when 14 =>  dataws      <=  '1';
                            sample_data <= word_11;
            when 15 =>  dataws      <=  '1';
                            sample_data <= word_12;
            when 16 =>  dataws      <=  '1';
                            sample_data <= word_13;
            when 17 =>  dataws      <=  '1';
                            sample_data <= word_14;
            when 18 =>  dataws      <=  '1';
                            sample_data <= word_15;
            when 19 =>  dataws      <=  '1';
                            sample_data <= word_16;
            when 20 =>  dataws      <=  '1';
                            sample_data <= word_17;
            when 21 =>  dataws      <=  '1';
                            sample_data <= word_18;
            when 22 =>  dataws      <=  '1';
                            sample_data <= word_19;
            when 23 =>  dataws      <=  '1';
                            sample_data <= word_20;
            when 24 =>  dataws      <=  '1';
                            sample_data <= word_21;
            when 25 =>  dataws      <=  '1';
                            sample_data <= word_22;
            when 26 =>  dataws      <=  '1';
                            sample_data <= word_23;
            when 27 =>  dataws      <=  '1';
                            sample_data <= word_24;
            when 28 =>  dataws      <=  '1';
                            sample_data <= word_25;
            when 29 =>  dataws      <=  '1';
                            sample_data <= word_26;
            when 30 =>  dataws      <=  '1';
                            sample_data <= word_27;
            when 31 =>  dataws      <=  '1';
                            sample_data <= word_28;
            when 32 =>  dataws      <=  '1';
                            sample_data <= word_29;
            when 33 =>  dataws      <=  '1';
                            sample_data <= word_30;
            when 34 =>  dataws      <=  '1';
                            sample_data <= word_31;
            when 35 =>  dataws      <=  '1';
                            sample_data <= word_32;
            when 36 =>  dataws      <=  '1';
                            sample_data <= word_33;
            when 37 =>  dataws      <=  '1';
                            sample_data <= word_34;
            when 38 =>  dataws      <=  '1';
                            sample_data <= word_35;
            when 39 =>  dataws      <=  '1';
                            sample_data <= word_36;
            when 40 =>  dataws      <=  '1';
                            sample_data <= word_37;
            when 41 =>  dataws      <=  '1';
                            sample_data <= word_38;
            when 42 =>  dataws      <=  '1';
                            sample_data <= word_39;
            when 43 =>  dataws      <=  '1';
                            sample_data <= word_40;
            when 44 =>  dataws      <=  '1';
                            sample_data <= word_41;
            when 45 =>  dataws      <=  '1';
                            sample_data <= word_42;
            when 46 =>  dataws      <=  '1';
                            sample_data <= word_43;
            when 47 =>  dataws      <=  '1';
                            sample_data <= word_44;
            when 48 =>  dataws      <=  '1';
                            sample_data <= word_45;
            when 49 =>  dataws      <=  '1';
                            sample_data <= word_46;
            when 50 =>  dataws      <=  '1';
                            sample_data <= word_47;
            when 51 =>  dataws      <=  '1';
                            sample_data <= word_48;
            when 52 =>  dataws      <=  '1';
                            sample_data <= word_49;
            when 53 =>  dataws      <=  '1';
                            sample_data <= word_50;
            when 54 =>  dataws      <=  '1';
                            sample_data <= word_51;
            when 55 =>  dataws      <=  '1';
                            sample_data <= word_52;
            when 56 =>  dataws      <=  '1';
                            sample_data <= word_53;
            when 57 =>  dataws      <=  '1';
                            sample_data <= word_54;
            when 58 =>  dataws      <=  '1';
                            sample_data <= word_55;
            when 59 =>  dataws      <=  '1';
                            sample_data <= word_56;
            when 60 =>  dataws      <=  '1';
                            sample_data <= word_57;
            when 61 =>  dataws      <=  '1';
                            sample_data <= word_58;
            when 62 =>  dataws      <=  '1';
                            sample_data <= word_59;
            when 63 =>  dataws      <=  '1';
                            sample_data <= word_60;
            when 64 =>  dataws      <=  '1';
                            sample_data <= word_61;
            when 65 =>  dataws      <=  '1';
                            sample_data <= word_62;
            when 66 =>  dataws      <=  '1';
                            sample_data <= word_63;
            when 67 =>  dataws      <=  '1';
                            sample_data <= word_64;
            when 68 =>  dataws      <=  '1';
                            sample_data <= word_65;
            when 69 =>  dataws      <=  '1';
                            sample_data <= word_66;
            when 70 =>  dataws      <=  '1';
                            sample_data <= word_67;
            when 71 =>  dataws      <=  '1';
                            sample_data <= word_68;
            when 72 =>  dataws      <=  '1';
                            sample_data <= word_69;
            when 73 =>  dataws      <=  '1';
                            sample_data <= word_70;
            when 74 =>  dataws      <=  '1';
                            sample_data <= word_71;

            when 75 to window_counter+3 =>  dataws      <=  '1';
                                                        case mode_bit3 is
                                                            --Upcounter
                                                            when "000"  =>  counter     <=  counter +'1';
                                                                                sample_data <=  counter;
                                                            --Downcounter
                                                            when "001"  =>  counter     <=  counter -'1';
                                                                                sample_data <=  counter;
                                                            --Constant AA55
                                                            when "010"  =>  sample_data <=  data_AA55;
                                                            --Stretch Mode
                                                            when "011"  =>  test_sample <=  test_sample +'1';
                                                                                sample_data <=  test_sample & test_sample;
                                                            --Fixed Mode
                                                            when "100"  =>  sample_data <=  input_data & input_data;
                                                            --Random Sequence
                                                            when "111"  =>  random_flag <=  '1';
                                                                                sample_data <=  data_in;
                                                            when others =>  sample_data <=  (others=>'0');
                                                        end case;
            when window_counter+4       =>  sample_data <=  word_trailer;
            when window_counter+5   =>  dataws      <=  '0';
                                                random_flag <=  '0';
                                                sample_data <=  (others=>'0');
            when time_period_counter    => count            <=   0;
            when others                     =>  dataws      <= '0';
                                                    sample_data <=  (others=>'0');
        end case;

        end if;
end if;

--  --Upcounter
--          if(start_bit='1' and mode_bit3="000") then
--          count       <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <= sample_data +'1';
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --Downcounter
--      if(start_bit='1' and mode_bit3="001") then
--          count       <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <= sample_data -'1';
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --AA55
--      if(start_bit='1' and mode_bit3="010") then
--          count   <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <=  data_AA55;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --Stretch mode
--      if(start_bit='1' and mode_bit3="011") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              test_sample <=  test_sample +'1';
--              sample_data <=  test_sample & test_sample;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--              test_sample <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--      --Fixed mode
--      if(start_bit='1' and mode_bit3="100") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <=  input_data & input_data;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--      --Random sequence generator
--      if(start_bit='1' and mode_bit3="111") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws          <=  '1';
--              random_flag     <=  '1';
--              sample_data     <=  data_in;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              random_flag <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;

--  end if;

end process;
data    <=  sample_data;
end Behavioral;
```

答: In VHDL you can't use variables in case statements as choices, like you did. It must be static expressions, like "001" or 34, not for example signal, like time_period_counter.

Title: Syntax error while running the code

Body:
The error is in the lines 431,451,452 and 455.

ERROR:- Line 431. Choice .to. is not a static expression.
 Line 451. Choice + is not a static expression.
 Line 452. Choice + is not a static expression.
 Line 455. Choice time_period_counter is not a static expression.

The code that i have attached is quite long but the logic is quite simple. It is regarding syntax of switch case.

Please help!!

----------------------------------------------------------------------------------
-- Company: IIST
-- Engineer: Leen Roque Robin
--
-- Create Date:    23:14:17 06/22/2017
-- Design Name:
-- Module Name:    data - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:     To create the corresponding output data as per the command received from the command_interface module
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity data_output is
    Port (  --Input signals
               Por              : in std_logic;
               sys_clk          : in std_logic;
               start_bit        : in std_logic;
               mode_bit1        : in std_logic_vector(2 downto 0);
               mode_bit2        : in std_logic_vector(2 downto 0);
               mode_bit3        : in std_logic_vector(2 downto 0);
               input_data       : in std_logic_vector(7 downto 0);
                card_id         : in std_logic_vector(7 downto 0);

            --Output signals
                clk             : out std_logic;
               pkt_start        : out std_logic;
               dataws           : out std_logic;
               data             : out std_logic_vector(15 downto 0)
--             random_flag      :out std_logic
           );
end data_output;

architecture Behavioral of data_output is
signal count                :   integer:=0;
signal time_period_counter  :   integer:=0;
signal window_counter       :   integer:=0;

constant data_AA55          :   std_logic_vector(15 downto 0):=x"AA55";
constant data_5555          :   std_logic_vector(15 downto 0):=x"5555";

constant word_1             :   std_logic_vector(15 downto 0):=x"F8DD";
constant word_2             :   std_logic_vector(15 downto 0):=x"4259";
signal word_3               :   std_logic_vector(15 downto 0);
constant word_4             :   std_logic_vector(15 downto 0):=x"5231";
signal word_5               :   std_logic_vector(15 downto 0);
signal word_6               :   std_logic_vector(15 downto 0);
signal word_7               :   std_logic_vector(15 downto 0);
signal word_8               :   std_logic_vector(15 downto 0):=x"F8DD";
signal word_9               :   std_logic_vector(15 downto 0):=x"F8DD";
signal word_10              :   std_logic_vector(15 downto 0):=x"F8DD";

constant word_11                :   std_logic_vector(15 downto 0):=x"00AA";
constant word_12                :   std_logic_vector(15 downto 0):=x"00AB";
constant word_13                :   std_logic_vector(15 downto 0):=x"00AC";
constant word_14                :   std_logic_vector(15 downto 0):=x"00AD";
constant word_15                :   std_logic_vector(15 downto 0):=x"00AE";
constant word_16                :   std_logic_vector(15 downto 0):=x"00AF";
constant word_17                :   std_logic_vector(15 downto 0):=x"00BA";
constant word_18                :   std_logic_vector(15 downto 0):=x"00BB";
constant word_19                :   std_logic_vector(15 downto 0):=x"00BC";
constant word_20                :   std_logic_vector(15 downto 0):=x"00BD";
constant word_21                :   std_logic_vector(15 downto 0):=x"00BE";
constant word_22                :   std_logic_vector(15 downto 0):=x"00BF";
constant word_23                :   std_logic_vector(15 downto 0):=x"00CA";
constant word_24                :   std_logic_vector(15 downto 0):=x"00CB";
constant word_25                :   std_logic_vector(15 downto 0):=x"00CC";
constant word_26                :   std_logic_vector(15 downto 0):=x"00CD";
constant word_27                :   std_logic_vector(15 downto 0):=x"00CE";
constant word_28                :   std_logic_vector(15 downto 0):=x"00CF";
constant word_29                :   std_logic_vector(15 downto 0):=x"00DA";
constant word_30                :   std_logic_vector(15 downto 0):=x"00DB";
constant word_31                :   std_logic_vector(15 downto 0):=x"00DC";
constant word_32                :   std_logic_vector(15 downto 0):=x"00DD";
constant word_33                :   std_logic_vector(15 downto 0):=x"00DE";
constant word_34                :   std_logic_vector(15 downto 0):=x"00DF";
constant word_35                :   std_logic_vector(15 downto 0):=x"00EA";
constant word_36                :   std_logic_vector(15 downto 0):=x"00EB";
constant word_37                :   std_logic_vector(15 downto 0):=x"00EC";
constant word_38                :   std_logic_vector(15 downto 0):=x"00ED";
constant word_39                :   std_logic_vector(15 downto 0):=x"00EE";
constant word_40                :   std_logic_vector(15 downto 0):=x"00EF";
constant word_41                :   std_logic_vector(15 downto 0):=x"00FA";
constant word_42                :   std_logic_vector(15 downto 0):=x"00FB";
constant word_43                :   std_logic_vector(15 downto 0):=x"00FC";
constant word_44                :   std_logic_vector(15 downto 0):=x"00FD";
constant word_45                :   std_logic_vector(15 downto 0):=x"00FE";
constant word_46                :   std_logic_vector(15 downto 0):=x"00FF";
constant word_47                :   std_logic_vector(15 downto 0):=x"01AA";
constant word_48                :   std_logic_vector(15 downto 0):=x"01AB";
constant word_49                :   std_logic_vector(15 downto 0):=x"01AC";
constant word_50                :   std_logic_vector(15 downto 0):=x"01AD";
constant word_51                :   std_logic_vector(15 downto 0):=x"01AE";
constant word_52                :   std_logic_vector(15 downto 0):=x"01AF";
constant word_53                :   std_logic_vector(15 downto 0):=x"01BA";
constant word_54                :   std_logic_vector(15 downto 0):=x"01BB";
constant word_55                :   std_logic_vector(15 downto 0):=x"01BC";
constant word_56                :   std_logic_vector(15 downto 0):=x"01BD";
constant word_57                :   std_logic_vector(15 downto 0):=x"01BE";
constant word_58                :   std_logic_vector(15 downto 0):=x"01BF";
constant word_59                :   std_logic_vector(15 downto 0):=x"01CA";
constant word_60                :   std_logic_vector(15 downto 0):=x"01CB";
constant word_61                :   std_logic_vector(15 downto 0):=x"01CC";
constant word_62                :   std_logic_vector(15 downto 0):=x"01CD";
constant word_63                :   std_logic_vector(15 downto 0):=x"01CE";
constant word_64                :   std_logic_vector(15 downto 0):=x"01CF";
constant word_65                :   std_logic_vector(15 downto 0):=x"01DA";
constant word_66                :   std_logic_vector(15 downto 0):=x"01DB";
constant word_67                :   std_logic_vector(15 downto 0):=x"01DC";
constant word_68                :   std_logic_vector(15 downto 0):=x"01DD";
constant word_69                :   std_logic_vector(15 downto 0):=x"01DE";
constant word_70                :   std_logic_vector(15 downto 0):=x"01DF";
constant word_71                :   std_logic_vector(15 downto 0):=x"01EA";
constant word_trailer               :   std_logic_vector(15 downto 0):=x"01FF";

signal word_6_7             :   std_logic_vector(31 downto 0);
signal word_8_9             :   std_logic_vector(31 downto 0);

--prf values
signal prf1_value           :   integer:=10417;
signal prf2_value           :   integer:=11161;
signal prf3_value           :   integer:=5581;
signal prf4_value           :   integer:=11161;
--window values
--window for prf1
signal prf1_width1          :   integer:=2816;
signal prf1_width2          :   integer:=3129;
signal prf1_width3          :   integer:=3441;
signal prf1_width4          :   integer:=3754;

--window for prf2
signal prf2_width1          :   integer:=1563;
signal prf2_width2          :   integer:=2813;
signal prf2_width3          :   integer:=4063;
signal prf2_width4          :   integer:=5313;

--window for prf3
signal prf3_width1          :   integer:=1094;
signal prf3_width2          :   integer:=1719;
signal prf3_width3          :   integer:=2344;
signal prf3_width4          :   integer:=2969;

--window for prf4
signal prf4_width1          :   integer:=1094;
signal prf4_width2          :   integer:=1719;
signal prf4_width3          :   integer:=2344;
signal prf4_width4          :   integer:=2969;

signal sample_data          :   std_logic_vector(15 downto 0);
signal test_sample          :   std_logic_vector(7 downto 0);
signal random_flag          :   std_logic;
signal data_in                  :  std_logic_vector(15 downto 0);
signal counter                  :  std_logic_vector(15 downto 0);

--Random Sequence generation
Component random_data_generator
Port(--Input signals
        por             :   in std_logic;
        sys_clk         :   in std_logic;
        random_flag     :   in std_logic;
        --Output signals
        random_data     :   out std_logic_vector(15 downto 0)

);
end component;

begin

A:  random_data_generator port map (por,sys_clk,random_flag,data_in);

    process(por,sys_clk)
    begin
    if(por='0') then
        time_period_counter     <= 0;
        window_counter          <= 0;

        word_3                      <=  (others=>'0');
        word_5                      <=  (others=>'0');
        word_6_7                        <= (others=>'0');
        word_8_9                        <= (others=>'0');
--      word_6                      <=  (others=>'0');
--      word_7                      <=  (others=>'0');
--      word_8                      <= (others=>'0');
--      word_9                      <=  (others=>'0');
        word_10                     <=  (others=>'0');

    elsif(falling_edge(sys_clk)) then
    --Finding word 3
    case card_id is
        when x"01"  =>  word_3  <=  x"F0F0";
        when x"02"  =>  word_3  <=  x"F00F";
        when x"03"  =>  word_3  <=  x"0FF0";
        when x"04"  =>  word_3  <=  x"0F0F";
        when others => word_3   <= x"0000";
    end case;
    --Finding word 10
    if(mode_bit3 = "011") then
        word_10(10 downto 8)    <=  "111";
    end if;
    if(mode_bit1 = "000") then
        word_10(3 downto 0) <=  "0000";
    elsif(mode_bit1 = "001") then
        word_10(3 downto 0) <=  "0001";
    elsif(mode_bit1 = "010") then
        word_10(3 downto 0) <=  "0010";
    elsif(mode_bit1 = "011") then
        word_10(3 downto 0) <=  "0011";
    end if;

    --Checking PRF
    case mode_bit1 is
        when "000"  =>  time_period_counter <= prf1_value;
            --Checking receive window
            case mode_bit2 is
                when "000"  => window_counter <= prf1_width1;
                when "001"  => window_counter <= prf1_width2;
                when "010"  => window_counter <= prf1_width3;
                when "011"  => window_counter <= prf1_width4;
                when others => window_counter <= prf1_width1;
            end case;

        when "001"  =>  time_period_counter <= prf2_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf2_width1;
                when "001"  => window_counter <= prf2_width2;
                when "010"  => window_counter <= prf2_width3;
                when "011"  => window_counter <= prf2_width4;
                when others => window_counter <= prf2_width1;
            end case;

        when "010"  =>  time_period_counter <= prf3_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf3_width1;
                when "001"  => window_counter <= prf3_width2;
                when "010"  => window_counter <= prf3_width3;
                when "011"  => window_counter <= prf3_width4;
                when others => window_counter <= prf3_width1;
            end case;

        when "011"  =>  time_period_counter <= prf4_value;
            case mode_bit2 is
                when "000"  => window_counter <= prf4_width1;
                when "001"  => window_counter <= prf4_width2;
                when "010"  => window_counter <= prf4_width3;
                when "011"  => window_counter <= prf4_width4;
                when others => window_counter <= prf4_width1;
            end case;
        when others =>  time_period_counter <=  prf1_value;
                        window_counter      <=  0;
        end case;
    end if;

    if(por='0') then
        test_sample     <= (others=>'0');
        sample_data     <= (others=>'0');
        pkt_start       <=  '0';
        dataws          <=  '0';
        count               <=  0;
        counter         <=  x"0000";
    elsif(falling_edge(sys_clk)) then

    if(start_bit='1') then
        count   <=  count+1;
        case count is
            when 1 to 2 =>  pkt_start   <=  '1';
                                dataws      <=  '0';
            when 3  =>  pkt_start   <=  '0';
                            dataws      <=  '0';
            when 4  =>  dataws      <=  '1';
                            word_5      <=  word_5+'1';
                            word_6_7        <=  word_6_7+'1';
                            word_8_9        <=  word_8_9+'1';
                            sample_data <= word_1;
            when 5  =>  dataws      <=  '1';
                            sample_data <= word_2;
            when 6  =>  dataws      <=  '1';
                            sample_data <= word_3;
            when 7  =>  dataws      <=  '1';
                            sample_data <= word_4;
            when 8  =>  dataws      <=  '1';
                            sample_data <= word_5;
            when 9  =>  dataws      <=  '1';
                            sample_data <= word_6_7(31 downto 16);
            when 10 =>  dataws      <=  '1';
                            sample_data <= word_6_7(15 downto 0);
            when 11 =>  dataws      <=  '1';
                            sample_data <= word_8_9(31 downto 16);
            when 12 =>  dataws      <=  '1';
                            sample_data <= word_8_9(15 downto 0);
            when 13 =>  dataws      <=  '1';
                            sample_data <= word_10;
            when 14 =>  dataws      <=  '1';
                            sample_data <= word_11;
            when 15 =>  dataws      <=  '1';
                            sample_data <= word_12;
            when 16 =>  dataws      <=  '1';
                            sample_data <= word_13;
            when 17 =>  dataws      <=  '1';
                            sample_data <= word_14;
            when 18 =>  dataws      <=  '1';
                            sample_data <= word_15;
            when 19 =>  dataws      <=  '1';
                            sample_data <= word_16;
            when 20 =>  dataws      <=  '1';
                            sample_data <= word_17;
            when 21 =>  dataws      <=  '1';
                            sample_data <= word_18;
            when 22 =>  dataws      <=  '1';
                            sample_data <= word_19;
            when 23 =>  dataws      <=  '1';
                            sample_data <= word_20;
            when 24 =>  dataws      <=  '1';
                            sample_data <= word_21;
            when 25 =>  dataws      <=  '1';
                            sample_data <= word_22;
            when 26 =>  dataws      <=  '1';
                            sample_data <= word_23;
            when 27 =>  dataws      <=  '1';
                            sample_data <= word_24;
            when 28 =>  dataws      <=  '1';
                            sample_data <= word_25;
            when 29 =>  dataws      <=  '1';
                            sample_data <= word_26;
            when 30 =>  dataws      <=  '1';
                            sample_data <= word_27;
            when 31 =>  dataws      <=  '1';
                            sample_data <= word_28;
            when 32 =>  dataws      <=  '1';
                            sample_data <= word_29;
            when 33 =>  dataws      <=  '1';
                            sample_data <= word_30;
            when 34 =>  dataws      <=  '1';
                            sample_data <= word_31;
            when 35 =>  dataws      <=  '1';
                            sample_data <= word_32;
            when 36 =>  dataws      <=  '1';
                            sample_data <= word_33;
            when 37 =>  dataws      <=  '1';
                            sample_data <= word_34;
            when 38 =>  dataws      <=  '1';
                            sample_data <= word_35;
            when 39 =>  dataws      <=  '1';
                            sample_data <= word_36;
            when 40 =>  dataws      <=  '1';
                            sample_data <= word_37;
            when 41 =>  dataws      <=  '1';
                            sample_data <= word_38;
            when 42 =>  dataws      <=  '1';
                            sample_data <= word_39;
            when 43 =>  dataws      <=  '1';
                            sample_data <= word_40;
            when 44 =>  dataws      <=  '1';
                            sample_data <= word_41;
            when 45 =>  dataws      <=  '1';
                            sample_data <= word_42;
            when 46 =>  dataws      <=  '1';
                            sample_data <= word_43;
            when 47 =>  dataws      <=  '1';
                            sample_data <= word_44;
            when 48 =>  dataws      <=  '1';
                            sample_data <= word_45;
            when 49 =>  dataws      <=  '1';
                            sample_data <= word_46;
            when 50 =>  dataws      <=  '1';
                            sample_data <= word_47;
            when 51 =>  dataws      <=  '1';
                            sample_data <= word_48;
            when 52 =>  dataws      <=  '1';
                            sample_data <= word_49;
            when 53 =>  dataws      <=  '1';
                            sample_data <= word_50;
            when 54 =>  dataws      <=  '1';
                            sample_data <= word_51;
            when 55 =>  dataws      <=  '1';
                            sample_data <= word_52;
            when 56 =>  dataws      <=  '1';
                            sample_data <= word_53;
            when 57 =>  dataws      <=  '1';
                            sample_data <= word_54;
            when 58 =>  dataws      <=  '1';
                            sample_data <= word_55;
            when 59 =>  dataws      <=  '1';
                            sample_data <= word_56;
            when 60 =>  dataws      <=  '1';
                            sample_data <= word_57;
            when 61 =>  dataws      <=  '1';
                            sample_data <= word_58;
            when 62 =>  dataws      <=  '1';
                            sample_data <= word_59;
            when 63 =>  dataws      <=  '1';
                            sample_data <= word_60;
            when 64 =>  dataws      <=  '1';
                            sample_data <= word_61;
            when 65 =>  dataws      <=  '1';
                            sample_data <= word_62;
            when 66 =>  dataws      <=  '1';
                            sample_data <= word_63;
            when 67 =>  dataws      <=  '1';
                            sample_data <= word_64;
            when 68 =>  dataws      <=  '1';
                            sample_data <= word_65;
            when 69 =>  dataws      <=  '1';
                            sample_data <= word_66;
            when 70 =>  dataws      <=  '1';
                            sample_data <= word_67;
            when 71 =>  dataws      <=  '1';
                            sample_data <= word_68;
            when 72 =>  dataws      <=  '1';
                            sample_data <= word_69;
            when 73 =>  dataws      <=  '1';
                            sample_data <= word_70;
            when 74 =>  dataws      <=  '1';
                            sample_data <= word_71;

            when 75 to window_counter+3 =>  dataws      <=  '1';
                                                        case mode_bit3 is
                                                            --Upcounter
                                                            when "000"  =>  counter     <=  counter +'1';
                                                                                sample_data <=  counter;
                                                            --Downcounter
                                                            when "001"  =>  counter     <=  counter -'1';
                                                                                sample_data <=  counter;
                                                            --Constant AA55
                                                            when "010"  =>  sample_data <=  data_AA55;
                                                            --Stretch Mode
                                                            when "011"  =>  test_sample <=  test_sample +'1';
                                                                                sample_data <=  test_sample & test_sample;
                                                            --Fixed Mode
                                                            when "100"  =>  sample_data <=  input_data & input_data;
                                                            --Random Sequence
                                                            when "111"  =>  random_flag <=  '1';
                                                                                sample_data <=  data_in;
                                                            when others =>  sample_data <=  (others=>'0');
                                                        end case;
            when window_counter+4       =>  sample_data <=  word_trailer;
            when window_counter+5   =>  dataws      <=  '0';
                                                random_flag <=  '0';
                                                sample_data <=  (others=>'0');
            when time_period_counter    => count            <=   0;
            when others                     =>  dataws      <= '0';
                                                    sample_data <=  (others=>'0');
        end case;

        end if;
end if;

--  --Upcounter
--          if(start_bit='1' and mode_bit3="000") then
--          count       <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <= sample_data +'1';
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --Downcounter
--      if(start_bit='1' and mode_bit3="001") then
--          count       <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <= sample_data -'1';
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --AA55
--      if(start_bit='1' and mode_bit3="010") then
--          count   <=  count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <=  data_AA55;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--  --Stretch mode
--      if(start_bit='1' and mode_bit3="011") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              test_sample <=  test_sample +'1';
--              sample_data <=  test_sample & test_sample;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--              test_sample <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--      --Fixed mode
--      if(start_bit='1' and mode_bit3="100") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws      <=  '1';
--              sample_data <=  input_data & input_data;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;
--
--      --Random sequence generator
--      if(start_bit='1' and mode_bit3="111") then
--          count<=count+1;
--          if(count=1) then
--              pkt_start   <=  '1';
--              dataws      <=  '0';
--          elsif(count=3) then
--              pkt_start   <=  '0';
--          elsif(count>=3 and count<(window_counter+4)) then
--              dataws          <=  '1';
--              random_flag     <=  '1';
--              sample_data     <=  data_in;
--          elsif(count=(window_counter+4)) then
--              dataws      <=  '0';
--              random_flag <=  '0';
--              sample_data <= (others=>'0');
--          elsif(count=time_period_counter) then
--              count       <=  0;
--          end if;
--      end if;

--  end if;

end process;
data    <=  sample_data;
end Behavioral;


问:
Doing groupby on cell values in pandas dataframe
I have a data frame with 99 columns from dx1-dx99 one column as LOS. dxi columns contain categorical codes and they don't have any order. Codes can occur in any column in a row. Codes can repeat in a column but they will not repeat in a row:

```<code>dx1 dx2 dx3 .   dx99    los
E10 I12 0 N18 R18       12
E10 I12 I31 E44 N17     7
E10 I12 N17 T86 0       5
I12 E10 N18 A04         1
E10 I12 B10 N18 Z99     4
E10 N18 Z76             1
E10 N18 Z99 N25 E78     8
</code>```

I want to calculate average of LOS for each code in the data frame. All I found was I can apply groupby() function on multiple columns. But that doesn't give me desired result. I need result in this format:

```<code>Codes    mean-LOS
E10      5.42
I12      7.6
N18      5.2
.
.
etc.
</code>```

Body:
I have a data frame with 99 columns from dx1-dx99 one column as LOS. dxi columns contain categorical codes and they don't have any order. Codes can occur in any column in a row. Codes can repeat in a column but they will not repeat in a row:

dx1 dx2 dx3 .   dx99    los
E10 I12 0 N18 R18       12
E10 I12 I31 E44 N17     7
E10 I12 N17 T86 0       5
I12 E10 N18 A04         1
E10 I12 B10 N18 Z99     4
E10 N18 Z76             1
E10 N18 Z99 N25 E78     8

I want to calculate average of LOS for each code in the data frame. All I found was I can apply groupby() function on multiple columns. But that doesn't give me desired result. I need result in this format:

Codes    mean-LOS
E10      5.42
I12      7.6
N18      5.2
.
.
etc.

Body:
You can use DataFrame.melt for reshape with groupby and aggregate mean:

df = df.melt('los', value_name='Codes')
#older version of pandas < 0.20.0
#df = pd.melt(df, 'los', value_name='Codes')
df = df.groupby('Codes', as_index=False)['los'].mean()
print (df)
   Codes        los
0      0   8.500000
1    A04   1.000000
2    B10   4.000000
3    E10   5.428571
4    E44   7.000000
5    E78   8.000000
6    I12   5.800000
7    I31   7.000000
8    N17   6.000000
9    N18   5.200000
10   N25   8.000000
11   R18  12.000000
12   T86   5.000000
13   Z76   1.000000
14   Z99   6.000000

If need rename column:

df = df.melt('los', value_name='Codes')
df = df.groupby('Codes')['los'].mean().reset_index(name='mean-LOS')
print (df)
   Codes   mean-LOS
0      0   8.500000
1    A04   1.000000
2    B10   4.000000
3    E10   5.428571
4    E44   7.000000
5    E78   8.000000
6    I12   5.800000
7    I31   7.000000
8    N17   6.000000
9    N18   5.200000
10   N25   8.000000
11   R18  12.000000
12   T86   5.000000
13   Z76   1.000000
14   Z99   6.000000


问:
Can I load incoming change sets without deleting sandbox in RTC
I have a stream with 40GB of data. Every time I am deleting the sandbox, accepting changesets and loading the sandbox.

Loading whole data is taking longer.

Is there anyway to accept the changesets without deleting sandbox and to build that, through Jenkins.

Do we have RTC plugin for Jenkins that loads sandbox in incremental manner (by accepting&loading only delta changesets).

答:
The Job configuration of that Jenkins RTC plugin does include an option:

"Delete directory before loading."

and:

"Accept latest changes before loading": When loading the jenkins build workspace from a RTC repository workspace, there is an option to configure whether to accept latest changes before loading. By default, this option is selected.

Check if, in your case, that option is selected or not.


问:
sed regular expression to replace value with variable of same name
I am trying to replace a some variables in a yml file.

Samepl.yml

```<code>spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ myVal }}
</code>```

I am using following command to replace all the values inside double braces eg: {{ var }}  with a environment variable of same name i.e value of: ${var} it should fail if variable is undefined. But no luck

```<code>cat sample.yml | sed -e "s/{{ \(.*\) }}/${\1:?}/g" > /tmp/a
</code>```

Any suggestions?

答:
With GNU awk for the 3rd arg to match():

```<code>$ myVal="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) && (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3] } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ foo }}

$ other="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) && (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3] } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ myVal }}
</code>```

or if you prefer:

```<code>$ myVal="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) { if (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3]} else {print "the sky is falling!"; exit} } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ foo }}

$ other="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) { if (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3]} else {print "the sky is falling!"; exit} } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
the sky is falling!
</code>```

Body:
I am trying to replace a some variables in a yml file.

Samepl.yml

spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ myVal }}

I am using following command to replace all the values inside double braces eg: {{ var }}  with a environment variable of same name i.e value of: ${var} it should fail if variable is undefined. But no luck

cat sample.yml | sed -e "s/{{ \(.*\) }}/${\1:?}/g" > /tmp/a

Any suggestions?

Body:
With GNU awk for the 3rd arg to match():

$ myVal="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) && (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3] } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ foo }}

$ other="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) && (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3] } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ myVal }}

or if you prefer:

$ myVal="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) { if (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3]} else {print "the sky is falling!"; exit} } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
  myval: {{ foo }}

$ other="foo" gawk 'match($0,/(.*{{\s*)(\S+)(\s*}}.*)/,a) { if (a[2] in ENVIRON) { $0 = a[1] ENVIRON[a[2]] a[3]} else {print "the sky is falling!"; exit} } 1' file
spring:
  metadataMap:
    instanceId: ${spring.application.name}:${randomvalue}
client:
  version: 1.0
the sky is falling!


问:
Trying to understand why my python script is skipping the second row in a csv file
I am putting together a python script to create an output of email addresses from a csv. For whatever reason, the script below is skipping the second row (row after the headers) and only recording the data I need after that row. For example, if the users in the csv file were:

```<code>Username:
test
admin
root
</code>```

The output would only be:

```<code>Emails:
admin@gmail.com
root@gmail.com
</code>```

Thus completely ignoring the first entry. Here is the code, any thoughts on the matter are greatly appreciated.

```<code>for filename in glob.glob(path):
    with open(filename, 'r') as f:
        reader = csv.DictReader(f)
        initialExportOneList = []
        for row in reader:
            iE = [row['Computer Name'], row['Username']]
            finalExportInOneList = [column['Username'] for column in reader if column['Username']]
            initialExportOneList.append(iE)

        domain = '@gmail.com'
        for i in finalExportInOneList:
            fullEmailCreation = i + domain
            print(fullEmailCreation)
</code>```

答: You iterate over reader inside the loop, to get finalExportInOneList.

Body:
I am putting together a python script to create an output of email addresses from a csv. For whatever reason, the script below is skipping the second row (row after the headers) and only recording the data I need after that row. For example, if the users in the csv file were:

Username:
test
admin
root

The output would only be:

Emails:
admin@gmail.com
root@gmail.com

Thus completely ignoring the first entry. Here is the code, any thoughts on the matter are greatly appreciated.

for filename in glob.glob(path):
    with open(filename, 'r') as f:
        reader = csv.DictReader(f)
        initialExportOneList = []
        for row in reader:
            iE = [row['Computer Name'], row['Username']]
            finalExportInOneList = [column['Username'] for column in reader if column['Username']]
            initialExportOneList.append(iE)

        domain = '@gmail.com'
        for i in finalExportInOneList:
            fullEmailCreation = i + domain
            print(fullEmailCreation)


问:
How to open an UIView in fullscreen mode with a tabbar?

this is my problem.

I have a tabBar application.

In first tab, i have a table.

On click on table it shows a modal
view.

To go back from modal view to first
view, i use

```<code>[self presentModalViewController:nw animated:YES];
</code>```

The problem is that if i click on the tabbar while is opened a modal view, it opens second view, but first view's table don't work because the modal view is still opened althoug it appear as closed.

It's a way to open modal view in fullscreen covering the tab bar?

Or also to check if modal view is closed or not from another view?

EDIT:
I tried with all of this code:

```<code> nw = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
 nw.modalInPopover = YES;
 nw.wantsFullScreenLayout = YES;
 nw.hidesBottomBarWhenPushed = YES;
 nw.contentSizeForViewInPopover = CGSizeMake(320, 480);
 nw.modalPresentationStyle = UIModalPresentationFullScreen;
 nw.view.frame = [[UIScreen mainScreen] applicationFrame];
 [nw.view setNeedsLayout];
</code>```

but nothing!!! It wan't go in fullscreen!!

Any idea please?

thanks,

alberto

答:
If the view you're presenting is full screen, this should obscure the tab bar. That said, you might need to re-size the view programmatically so that it's the same size as the UIWindow.

You should be able to do something along the lines of...

```<code>[nw setFrame:[[UIScreen mainScreen] applicationFrame]];
[nw setNeedsLayout];
</code>```

...to achieve this. (Sorry, I'm on a Windows box at the moment, so I can't confirm this. Hopefully someone will provide any tweaks if required.)

You should then dismiss the initial modal view via a delegate method in the originating class. (See the "Dismissing a Modal View Controller" section of Apple's View Controller Programming Guide for iOS.) The originating class would then dispose of the modal view.

ContentLicense: CC BY-SA 2.5

Body:
this is my problem.

I have a tabBar application.

In first tab, i have a table.

On click on table it shows a modal
view.

To go back from modal view to first
view, i use

[self presentModalViewController:nw animated:YES];

The problem is that if i click on the tabbar while is opened a modal view, it opens second view, but first view's table don't work because the modal view is still opened althoug it appear as closed.

It's a way to open modal view in fullscreen covering the tab bar?

Or also to check if modal view is closed or not from another view?

EDIT:
I tried with all of this code:

 nw = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
 nw.modalInPopover = YES;
 nw.wantsFullScreenLayout = YES;
 nw.hidesBottomBarWhenPushed = YES;
 nw.contentSizeForViewInPopover = CGSizeMake(320, 480);
 nw.modalPresentationStyle = UIModalPresentationFullScreen;
 nw.view.frame = [[UIScreen mainScreen] applicationFrame];
 [nw.view setNeedsLayout];

but nothing!!! It wan't go in fullscreen!!

Any idea please?

thanks,

alberto

Body:
If the view you're presenting is full screen, this should obscure the tab bar. That said, you might need to re-size the view programmatically so that it's the same size as the UIWindow.

You should be able to do something along the lines of...

[nw setFrame:[[UIScreen mainScreen] applicationFrame]];
[nw setNeedsLayout];

...to achieve this. (Sorry, I'm on a Windows box at the moment, so I can't confirm this. Hopefully someone will provide any tweaks if required.)

You should then dismiss the initial modal view via a delegate method in the originating class. (See the "Dismissing a Modal View Controller" section of Apple's View Controller Programming Guide for iOS.) The originating class would then dispose of the modal view.


问:
ASP Classic SQL Server XML format with Stored Procedure and Parameters
I'm trying to modify the routine suggested by John here, actually I did not changed anything, I just added a parameter, but I get

```<code>ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range,
or are in conflict with one another.

/test/test_xml.asp, line 19
</code>```

where line 19 contains:

```<code>ocmd.Parameters.Append paramTotals
</code>```

I tried also in other way, like

```<code>ocmd.Parameters("@ID").value=1030
</code>```

but I get following error:

```<code>Microsoft OLE DB Provider for SQL Server error '80040e21'
Procedure or function 'spTEST_XML' expects parameter '@ID', which was not supplied.
/test/test_xml.asp, line 20
</code>```

where in line 20 there is

```<code>oCmd.Execute , , 1025
</code>```

While, if I remove the parameter it works perfectly....

here the full routine

```<code>Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = "Provider=sqloledb;server=TEST;Database=test;User ID=sa;Password=test"
oCmd.Properties("Output Stream") = oXML
oXml.async = false
oCmd.CommandText = "spTEST_XML"
ocmd.CommandType=4
Set paramTotals = ocmd.CreateParameter("@ID", adInteger, adParamInput, , 1030)
ocmd.Parameters.Append paramTotals
oCmd.Execute , , 1025
Response.ContentType="text/xml"
Response.Write("<?xml version='1.0' encoding='utf-8'?>")
Response.Write oXML.xml
Set oXML = Nothing
Set oCmd = Nothing
</code>```

while here the top of the StoredProcedure

```<code>CREATE PROCEDURE [dbo].[spTEST_XML]
(
    @ID     int
)
AS
BEGIN
Declare @SDT datetime = sysdatetime()

if @ID is null
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND downloaded is null
    end
else
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND ID>=@ID
    end

select
    payment.id reference_id,
    payment.SMSRN SellingManagerSalesRecordNumber,
    cast(dateadd(hh,2,payment.payment_date) as date) payment_date_CET,
    payment.receiver_email,
    payment.auction_buyer_id,
    payment.payer_email,
    format(payment.mc_gross/XC,'N2') Payment_EUR,
    format(payment.mc_fee/XC,'N2') Fees_EUR,
    format((payment.mc_gross-payment.mc_fee)/xc,'N2') Net_EUR,
    format(payment.mc_handling/xc,'N2') Handling_EUR,
    format(payment.mc_shipping/xc,'N2') Shipping_EUR,
    payment.payment_status,
    payment.num_cart_items,
    payment.memo,
    payment.case_id,
    payment.mc_currency,
    payment.mc_gross,
    payment.mc_fee,
    payment.mc_handling,
    payment.mc_shipping,
    payment.payment_date
from
(
    select distinct
        p.id,p.payment_date, p.auction_buyer_id, p.mc_currency, p.mc_gross, p.mc_fee, p.payer_email, p.receiver_email, s.sellingmanagersalesrecordnumber SMSRN,
        coalesce(p.mc_handling,0) mc_handling, p.mc_shipping, p.payment_status,
        p.num_cart_items, p.memo, p.case_id, p.case_type, p.case_creation_date,
        p.case_closed,
        coalesce(CAST ((Select top (1) rate from dbo.EurRates r where r.Currency=p.mc_currency and r.FXDate<=p.payment_date) as Decimal (10,4)),1) XC
    from dbo.PayPal p
    left join dbo.eBaySales s   on s.referenceID=p.txn_id
    where p.Validation='VERIFIED'
    and p.downloaded=@SDT
) as Payment
order by receiver_email asc, payment_date desc
FOR XML AUTO , ROOT ('PaymentsArray') , ELEMENTS
</code>```

END

答:
Your SP seems OK, no need to modify, it's XML compliant.

However the value 1025 you passed Execute method as options parameter corresponds to adCmdText + adExecuteStream is not suitable for your command.

Instead, it must be adCmdStoredProc + adExecuteStream which equals to 1028.

So, the following code should work for you.

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = "Provider=sqloledb;server=TEST;Database=test;User ID=sa;Password=test"
oCmd.Properties("Output Stream") = oXML
oXml.async = false
oCmd.CommandText = "spTEST_XML"
ocmd.CommandType= 4
Set paramTotals = ocmd.CreateParameter("@ID", adInteger, adParamInput, , 0)
ocmd.Parameters.Append paramTotals
oCmd.Execute , , 4 + 1024 ' adCmdStoredProc + adExecuteStream
Response.ContentType="text/xml"
Response.Write("<?xml version='1.0' encoding='utf-8'?>")
Response.Write oXML.xml
Set oXML = Nothing
Set oCmd = Nothing
```

Body:
I'm trying to modify the routine suggested by John here, actually I did not changed anything, I just added a parameter, but I get

ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range,
or are in conflict with one another.

/test/test_xml.asp, line 19

where line 19 contains:

ocmd.Parameters.Append paramTotals

I tried also in other way, like

ocmd.Parameters("@ID").value=1030

but I get following error:

Microsoft OLE DB Provider for SQL Server error '80040e21'
Procedure or function 'spTEST_XML' expects parameter '@ID', which was not supplied.
/test/test_xml.asp, line 20

where in line 20 there is

oCmd.Execute , , 1025

While, if I remove the parameter it works perfectly....

here the full routine

Set oXML = Server.CreateObject("MSXML2.DomDocument.6.0")
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = "Provider=sqloledb;server=TEST;Database=test;User ID=sa;Password=test"
oCmd.Properties("Output Stream") = oXML
oXml.async = false
oCmd.CommandText = "spTEST_XML"
ocmd.CommandType=4
Set paramTotals = ocmd.CreateParameter("@ID", adInteger, adParamInput, , 1030)
ocmd.Parameters.Append paramTotals
oCmd.Execute , , 1025
Response.ContentType="text/xml"
Response.Write("<?xml version='1.0' encoding='utf-8'?>")
Response.Write oXML.xml
Set oXML = Nothing
Set oCmd = Nothing

while here the top of the StoredProcedure

CREATE PROCEDURE [dbo].[spTEST_XML]
(
    @ID     int
)
AS
BEGIN
Declare @SDT datetime = sysdatetime()

if @ID is null
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND downloaded is null
    end
else
    begin
        update dbo.PayPal set downloaded=@SDT where Validation='VERIFIED' AND ID>=@ID
    end

select
    payment.id reference_id,
    payment.SMSRN SellingManagerSalesRecordNumber,
    cast(dateadd(hh,2,payment.payment_date) as date) payment_date_CET,
    payment.receiver_email,
    payment.auction_buyer_id,
    payment.payer_email,
    format(payment.mc_gross/XC,'N2') Payment_EUR,
    format(payment.mc_fee/XC,'N2') Fees_EUR,
    format((payment.mc_gross-payment.mc_fee)/xc,'N2') Net_EUR,
    format(payment.mc_handling/xc,'N2') Handling_EUR,
    format(payment.mc_shipping/xc,'N2') Shipping_EUR,
    payment.payment_status,
    payment.num_cart_items,
    payment.memo,
    payment.case_id,
    payment.mc_currency,
    payment.mc_gross,
    payment.mc_fee,
    payment.mc_handling,
    payment.mc_shipping,
    payment.payment_date
from
(
    select distinct
        p.id,p.payment_date, p.auction_buyer_id, p.mc_currency, p.mc_gross, p.mc_fee, p.payer_email, p.receiver_email, s.sellingmanagersalesrecordnumber SMSRN,
        coalesce(p.mc_handling,0) mc_handling, p.mc_shipping, p.payment_status,
        p.num_cart_items, p.memo, p.case_id, p.case_type, p.case_creation_date,
        p.case_closed,
        coalesce(CAST ((Select top (1) rate from dbo.EurRates r where r.Currency=p.mc_currency and r.FXDate<=p.payment_date) as Decimal (10,4)),1) XC
    from dbo.PayPal p
    left join dbo.eBaySales s   on s.referenceID=p.txn_id
    where p.Validation='VERIFIED'
    and p.downloaded=@SDT
) as Payment
order by receiver_email asc, payment_date desc
FOR XML AUTO , ROOT ('PaymentsArray') , ELEMENTS

END


问:
Excel - How to create a formula to return a cell to the right of the result of another formula
Basically, I have this formula in a cell to return the very first non 0 value in a row:

=INDEX('Financials Cashflow Year'!C30:M30,MATCH(TRUE,INDEX('Financials Cashflow Year'!C30:M30<>0,),0))

I would like a formula to return the value of the cell on the right of the one picked up by this very first formula.

Say we have sheet 1 first row:

```<code>0 0 0 4 3 2
</code>```

Sheet 2 I would like to see with the formulas. Something scalable.

```<code>4 3 2
</code>```

答:
```<code>=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+1)
</code>```

Would give you the value of the cell one to the right of the first formula, but since it looks like you're looking for something more dynamic, this wouldn't work out incredibly well, for the cell two to the right of the first formula, you'd need this:

```<code>=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+2)
</code>```

Your best bet for grabbing out all cells to the right of the shown formula would be either transposing and filtering or using VBA, example for VBA:

```<code>Sub toRightOfZeros()

    Dim rng, cell As Range
    Dim startCellCol, destCellLocX As Integer
    Dim ValsArr() As String
    Dim wb As Workbook
    Dim foundNotZero As Boolean

    Set wb = ThisWorkbook
    destCellLocX = 1
    foundNotZero = False

    With wb.Sheets("Sheet1")
        Set rng = .Range(.Cells(30, 3), .Cells(30, 13))
    End With

    For Each cell In rng
        If foundNotZero = False Then
            If Not cell.Value = 0 Then
                foundNotZero = True
                startCellCol = cell.Column
                Exit For
            End If
        End If
    Next

    With wb.Sheets("Sheet1")
        Set rng = .Range(.Cells(30, startCellCol), .Cells(30, 13))
    End With

    For Each cell In rng
        With wb.Sheets("Sheet2")
            .Cells(1, destCellLocX).Value = cell.Value
        End With
        destCellLocX = destCellLocX + 1
    Next

End Sub
</code>```

Input(In C30:M30): 0 0 0 0 365 788 940 239 12 0 99

Output(On Sheet 2): 365 788 940 239 12 0 99

Body:
Basically, I have this formula in a cell to return the very first non 0 value in a row:

=INDEX('Financials Cashflow Year'!C30:M30,MATCH(TRUE,INDEX('Financials Cashflow Year'!C30:M30<>0,),0))

I would like a formula to return the value of the cell on the right of the one picked up by this very first formula.

Say we have sheet 1 first row:

0 0 0 4 3 2

Sheet 2 I would like to see with the formulas. Something scalable.

4 3 2

Body:
=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+1)

Would give you the value of the cell one to the right of the first formula, but since it looks like you're looking for something more dynamic, this wouldn't work out incredibly well, for the cell two to the right of the first formula, you'd need this:

=INDEX(C30:M30,MATCH(TRUE,INDEX(C30:M30<>0,),0)+2)

Your best bet for grabbing out all cells to the right of the shown formula would be either transposing and filtering or using VBA, example for VBA:

Sub toRightOfZeros()

    Dim rng, cell As Range
    Dim startCellCol, destCellLocX As Integer
    Dim ValsArr() As String
    Dim wb As Workbook
    Dim foundNotZero As Boolean

    Set wb = ThisWorkbook
    destCellLocX = 1
    foundNotZero = False

    With wb.Sheets("Sheet1")
        Set rng = .Range(.Cells(30, 3), .Cells(30, 13))
    End With

    For Each cell In rng
        If foundNotZero = False Then
            If Not cell.Value = 0 Then
                foundNotZero = True
                startCellCol = cell.Column
                Exit For
            End If
        End If
    Next

    With wb.Sheets("Sheet1")
        Set rng = .Range(.Cells(30, startCellCol), .Cells(30, 13))
    End With

    For Each cell In rng
        With wb.Sheets("Sheet2")
            .Cells(1, destCellLocX).Value = cell.Value
        End With
        destCellLocX = destCellLocX + 1
    Next

End Sub

Input(In C30:M30): 0 0 0 0 365 788 940 239 12 0 99

Output(On Sheet 2): 365 788 940 239 12 0 99


问:
mysql date is different when print from php
I have field with type (timestamp) and default CURRENT_TIMESTAMP, the date is correct when I browsing records with phpMyAdmin but when I tried to display it by PHP file it displayed incorrect date

date in MySQL 2017-07-05 10:28:12

date in PHP 2017-06-23 09:51:31

using below query

```<code>SELECT u.date FROM table u
</code>```

the global time zone of MySQL server is (SYSTEM) and I didn't change

PHP code

```<code><?php
include("../config.php");
$sql = mysql_query("sql query");
var_dump(mysql_fetch_array($sql));
?>
</code>```

Any support?

SOLUTION

If you face this problem you have to do the following:

Instead of mysql use PDO or mysqli_* functions and this will solve the problem without setting timezones either in your MySQL server or PHP files.

答:
There must be some other issue (more to the code 'picture', perhaps? ... or some other config/setting?), as I cannot reproduce.

Here's my sample data:

Here's the structure for the date column:

The PHP code that I used:

```<code>$dsn = 'mysql:host=localhost;dbname=test';

try {
    $conn = new PDO($dsn, 'root', 'xxxxx');
} catch (PDOException $e) {
    echo 'Error: ' . $e->getMessage();
    die();
}

$stmt = $conn->prepare("SELECT t.date FROM tryme t");
$stmt->execute();
var_dump($stmt->fetchAll());
</code>```

...and the output: (note that I used PDO handling in the above PHP code, the output would be similar if mysqli was used)

```<code>array(5) {
  [0]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [1]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [2]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [3]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [4]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
}
</code>```

UPDATE:

Example mysqli code, instead of PDO, to achieve the same output:

```<code>$db = new mysqli('localhost', 'root', 'xxxxx', 'test');
$result = $db->query("SELECT t.date FROM tryme t");

$rows = [];

while ( $row = $result->fetch_array() ) {
    $rows[] = $row;
}

var_dump($rows);
</code>```

Body:
I have field with type (timestamp) and default CURRENT_TIMESTAMP, the date is correct when I browsing records with phpMyAdmin but when I tried to display it by PHP file it displayed incorrect date

date in MySQL 2017-07-05 10:28:12

date in PHP 2017-06-23 09:51:31

using below query

SELECT u.date FROM table u

the global time zone of MySQL server is (SYSTEM) and I didn't change

PHP code

<?php
include("../config.php");
$sql = mysql_query("sql query");
var_dump(mysql_fetch_array($sql));
?>

Any support?

SOLUTION

If you face this problem you have to do the following:

Instead of mysql use PDO or mysqli_* functions and this will solve the problem without setting timezones either in your MySQL server or PHP files.

Body:
There must be some other issue (more to the code 'picture', perhaps? ... or some other config/setting?), as I cannot reproduce.

Here's my sample data:

Here's the structure for the date column:

The PHP code that I used:

$dsn = 'mysql:host=localhost;dbname=test';

try {
    $conn = new PDO($dsn, 'root', 'xxxxx');
} catch (PDOException $e) {
    echo 'Error: ' . $e->getMessage();
    die();
}

$stmt = $conn->prepare("SELECT t.date FROM tryme t");
$stmt->execute();
var_dump($stmt->fetchAll());

...and the output: (note that I used PDO handling in the above PHP code, the output would be similar if mysqli was used)

array(5) {
  [0]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [1]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [2]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [3]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
  [4]=>
  array(2) {
    ["date"]=>
    string(19) "2017-07-05 14:45:51"
    [0]=>
    string(19) "2017-07-05 14:45:51"
  }
}

UPDATE:

Example mysqli code, instead of PDO, to achieve the same output:

$db = new mysqli('localhost', 'root', 'xxxxx', 'test');
$result = $db->query("SELECT t.date FROM tryme t");

$rows = [];

while ( $row = $result->fetch_array() ) {
    $rows[] = $row;
}

var_dump($rows);