-5

i have texblocks wn01, wn02, wn03 .... wn15. Every field has text="0" If field wn01.text 0 or "" i want to enter value of przerzucanie. If field wn01.text other value, than check next textblock.text But if statement doesnt enter, i=1,s=01, string.operator==returned false. i tried ("wn"+s).Text but is not recognized

private void przerzucanie_wyniku()
{
    for (int i = 1; i < 16; i++)
    {
        string s = i.ToString("00");
        if ("wn"+s==null||"wn"+s=="0")
        {
            "wn"+s.Text = przerzucanie;

            break;
        }
    }
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • Can you use English names for method names, it will maybe give us a clue regarding what you are trying to achieve, something like FlipTheResult() ? – Zoran Basic Apr 14 '17 at 09:27
  • in another methods i created double a,b. dwade_w1=a*b, przerzucanie= Math.Round(dwade_w1, 4).ToString(); they i call przerzucanie_wyniku(); example przerzucanie=3.05, then i want put 3.05 in wn01 if it is empty or have 0. When <>0,empty i want to find next empty control textblock. wn01 ... wn15 i my historical list of przerzucanie values. I do not know how to write the code to program know "wn"+s is name of textblock – pawelstack Apr 14 '17 at 09:35
  • Are wn01, wn02 string variables? It looks to me like you need an array of string: string[] wn = new wn[16]; Then you can assign a value to: wn[i] = "przerzucanie" where i is the one from for loop – Zoran Basic Apr 14 '17 at 09:45
  • wn01, 02, 03, ... 15 are textblocks. – pawelstack Apr 14 '17 at 10:03

4 Answers4

2

"wn" + something else can't ever be null or not start with wn.

What you are doing I think is trying to find the textbox with a specific name instead of concatenating strings. If that is what you need, you have to walk the visual tree to find it. Here an example how to do that in WPF.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • i have texblocks, they are historical memory of przerzucanie, wn01 has value of first counting, wn02 second value of przerzucanie, wn03 .... . If wn01 is <>0 or <>"" then check wn02, if wn02=0 then wn02=przerzucanie, if not 0 or empty the check wn03 and next, next – pawelstack Apr 14 '17 at 08:05
0

This will never be true:

        if ("wn"+s==null||"wn"+s=="0")

This will always show "wn*".

Carra
  • 17,808
  • 7
  • 62
  • 75
0

You can try:

string w = "wn" + s;

if(w==null||w=="0"){}
Jestin
  • 79
  • 2
  • 11
0

answear is:

for (int i = 0; i < 15; i++)
            {
                TextBlock tb = (TextBlock)s7.Children[i];
                if (tb.Text == "0")
                {
                    tb.Text = przerzucanie.ToString();
                    break;
                }