c# - Run-Time Calculation -


i working on windows forms application. have 3 buttons. have written method calculates new location each button. had errors (explained after code). method is:

    random random = new random();     public int setpointlocation()     {         int x1 = x2 - 20;         int x2;         int x3 = x2 + 20;           int y1 = y2 - 1;         int y2 = random.next(0, 2);         int y3 = y2 + 1;          return x2 = (((x3 - x1) * (y2 - y1)) / y3 - y1) + x1;     } 

the errors :

cannot use local variable 'x2' before declared.

cannot use local variable 'y2' before declared.

so rearranged method's block:

    random random = new random();     public int setpointlocation()     {         int x2;         int x1 = x2 - 20;         int x3 = x2 + 20;          int y2 = convert.toint32((picbox.name).remove(0, 10));         int y1 = y2 - 1;         int y3 = y2 + 1;          return x2 = (((x3 - x1) * (y2 - y1)) / y3 - y1) + x1;     } 

now errors get:

"use of unassigned local variable 'x2'".

the formula i've used way of finding median frequency tables "statistics". 'x2' unknown , want calculate @ run-time, because 'x2' has no value, can't set 'x1', , 'x3'. solution problem?!

it sounds want pass x2 in parameter. can call function when know x2 supose be.

random random = new random(); public int setpointlocation(int x2) {     int x1 = x2 - 20;     int x3 = x2 + 20;      int y2 = convert.toint32((picbox.name).remove(0, 10));     int y1 = y2 - 1;     int y3 = y2 + 1;      // return x2 needs     return (((x3 - x1) * (y2 - y1)) / y3 - y1) + x1; } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -