c# - How to calculate with text boxes and skip empty text boxes? -


i have count money , have created textboxes user can input how many 1 euro coins has. (and 2 euro, 5 euro, etc) want calculate total, if textbox empty, can't count whit it. have tried ways won't work because program automatically start counting every input.

to keep short, want skip empty textboxes during calculation.

now have this:

int32 aa = int32.parse(textbox1.text); // 5 c int32 ba = int32.parse(textbox2.text); // 10 c int32 ca = int32.parse(textbox3.text); // 20 c int32 da = int32.parse(textbox4.text); // 50 c int32 ea = int32.parse(textbox5.text); // 1 e int32 fa = int32.parse(textbox6.text); // 2 e int32 ga = int32.parse(textbox7.text); // 5 e int32 ha = int32.parse(textbox8.text); // 10 e int32 ia = int32.parse(textbox9.text); // 20 e int32 ja = int32.parse(textbox10.text); // 50 e int32 ka = int32.parse(textbox11.text); // 100 e int32 total = ((aa * 5) + (ba * 10) + (ca * 20) + (da * 50) + (ea * 100) + (fa * 200) + (ga * 500) + (ha * 1000) + (ia * 2000) + (ja * 5000) + (ka * 100000)) / 100; richtextbox1.appendtext("\r\ntotaal: € " + total.tostring()); 

but doesn't work, because there empty boxes ;)

i hope can give me simple solution.

i think should use approch:

    var list = new list<tuple<textbox, decimal>>(){             tuple.create(textbox1, 0.05m),             tuple.create(textbox2, 0.1m),             tuple.create(textbox3, 0.2m),             tuple.create(textbox4, 0.5m),             tuple.create(textbox5, 1m),             tuple.create(textbox6, 2m),             tuple.create(textbox7, 5m),             tuple.create(textbox8, 10m),             tuple.create(textbox9, 20m),             tuple.create(textbox10, 50m),             tuple.create(textbox11, 100m),         };     decimal sum = list.sum(tuple =>{          int = 0;         int.tryparse(tuple.item1.text, out a);         return * tuple.item2;     }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -