449,282 Members | 1,253 Online
Need help? Post your question and get tips & solutions from a community of 449,282 IT Pros & Developers. It's quick & easy.

# global variable

 P: n/a Hi, after reading up, c# doesnt appear to use gloal variables. Alot of post advise against them also. So Im wondering how to get around this. Im trying to do a calculation, retain the result, do another calculation then add the result to my retained value etc. my values: Im backing then laying horses. So I back first, say with a return of £20 if it wins. Then I lay the horse with an offset bet giving me an overall return of £1. Ok, so I need to retain this value, at the momment I put it in textbox 'a'. Now say on the same horse I bet again. Same bet £20 if it wins, except Ive got to add my £1 giving £21. Ok so far, but I must retain the £20 outcome for this bet as it is used to calculate the offset bet. Not the £21. At the momment Im putting this figure into textbox 'b'. Ive written a class to do all the calcs. These calcs are done when a button is clicked, so once clicked the variables go out of focus, whence putting the values in a text box. But this doesnt feel very proffesional. Also I have to use another text box to retain the first odds backed a, so I can check that the lay odds are smaller. Hope you get the jist. Can anybody advise if there is a better way to do this. Regards Robert Jun 2 '07 #1
13 Replies

 P: n/a On Sat, 02 Jun 2007 09:45:07 -0700, Ro********@yahoo.co.uk

 P: n/a Hi, thanks for a quick reply. I know what you meen, I did try that but I found that between the click events I lost the values, Im guessing because they go out of focus. Does this sound right. Regards Robert Jun 2 '07 #3

 P: n/a On Sat, 02 Jun 2007 10:02:35 -0700, Ro********@yahoo.co.uk

 P: n/a

 P: n/a Sorry Ive really messed this question up. Ok here is a simplified version of my cass. using System; using System.Collections.Generic; using System.Text; namespace exceltest.Tasks { public class returns { public double backprice; public double layprice; public double back; public double lay; public double totReturn; public string bet; public void backbet() { back = ((backprice - 1) * 5); totReturn += back; bet = "on"; } public void laybet() { lay = ((layprice - 1) * 5); totReturn += lay; bet = "on"; } public void offsetback() { // horse backed = (profit+stake(original stake * original odds) * odds-1(total return - stake) - return // horse backed = (profit+stake(original stake * original odds) * odds-1(total return - stake) - return lay = (((back + 5) / layprice) * (layprice - 1)); totReturn -= lay; bet = "off";"; } } } with buttonbackbet I use rt.backprice = 4.1; rt.backbet(); making back within the class = 15.50. and totreturn = 15.50. then with button2laybet I use rt.layprice = 4; rt.offsetback(); which should make totreturn = 0.13p. This doesnt happen though because, the back and totreturn from the backbet havnt been retained. I hope this is better. regards robert Jun 2 '07 #6

 P: n/a

 P: n/a lay button = returns rt = new returns(); rt.totReturn = 15.50; rt.back = 15.50; rt.layprice = 4; rt.offsetback(); back button = returns rt = new returns(); rt.backbet(); totreturn = 15.50. the class is called returns. Regards Robert Jun 2 '07 #8

 P: n/a

 P: n/a