C# get average of a set of numericalupdowns, excclude 0's

http://gyazo.com/246cafd03301ba69d4e4e74251737a3e
~so my form will be filled with numeric updowns
~now the number (of numericupdowns) used by the user of the program can vary (a lot) some may use 5 some 15
~I need to take those numbers in the numeric updown and get the average of each column
but
~how to I code it where it will discard the number if the value = 0
~I want the code to be clean there was a VERY MESSY alternative (adding switches for every updown) but i would like to learn from people smarter than me !
Eat Mold. Subway

All right i see that the code you use is more complicated.
Firstly i would advise you to collect all numerical controls to collection. It will prevent you from empty result collection:
List<NumericUpDown> numList = new List<NumericUpDown>();
foreach (Control c in this.Controls)
if (c.GetType() == typeof(NumericUpDown))
NumericUpDown n = (NumericUpDown)c;
numList.Add(n);
Then remove numbers higher then 0 in the time of groupping results ( default average is zero here ):
var result = numList.GroupBy(num => num.Location.X, n => n.Value).Select(r => new
ColumnNo = r.Key,
ColumnAverage = r.Where(x => x > 0).DefaultIfEmpty(0).Average()
}).ToList();
Finnally sorting result collection will make the same order of results as columns are (from left to right)
result.Sort((a, b) => a.ColumnNo.CompareTo(b.ColumnNo));
Now result collection should contain correct results and have the size of the number of columns, so for example:
if(result.Count > 0)
label1.Text = "AVG: " + result[0].ColumnAverage;
Shows the average of the first column. It is also good practise to check whether result collection is not empty.
Thank you so much! how do i put this on a loop without a timer? because a timer is way to glitchy
Eat Mold. Subway

Similar Messages

  • Getting the average of a set of numbers, confused by file IO, please help!

    What i need to do is get the average of a set of numbers, the problem is that i am reading these numbers in from files in different directories where each file returns a number, and the average for the directory is the numbers for each file in that directory added together and divided by the number of files in that directory.
    public static HashMap readDir(File path, HashMap map) throws IOException{
            File files[] = path.listFiles();
            float totalForDirectory = 0;
             int common = 0;
             int count = 0;
                    if(files != null && files.length > 0) {
                              for(int i=0; i<files.length; i++) {
                                    if(files.isDirectory()) {
    readDir(files[i], map);
    } else {
    //trying to count the number of files in the directory
    count++;
    totalForDirectory =(total(common, totalF1(), totalF2(files[i])));
    readFile(files[i]);
    //will contain pathname, and the average
    map.put(path.getCanonicalPath(), totalForDirectory);
    return map;
    In the above code, totalForDirectory contains the number for each file, i want to add together the result of this variable for each file, "file[i]" in the directory, and divide that by the number of files in that directory.
    Id appreciate any help
    Thanks

    What you want, It seems to me, is a recursive routine (for directories) which returns both a total and a filecount. Then these can be totalled at each level (togther with the count for each file).
    Probably the best approach is to pass a small object in which the totals are accumulated.
    Define a class something like:
    public class Accumulator {
       int count;
       int total;
       public double mean() {
          return total / count;
      public void add(Accumulator add) {
         count += add.count;
         total += add.total;
       public void add(int numberFromFile) {
          count++;
         total += numberFromFile();
      }Create an instance of this at the start of your scan directory method, and pass it when you call make the recursion. At the end of the scan the method would use the first add method to add it's local totals to the hight level total.
    Obviously you create an Accumulator for the first scan directory call which becomes the grand total.

  • How to make labview program to get average value of 200 reading from multimeter (by using loop)

    Hello
    How to make labview program to get average value of 200 reading from multimeter (I using using loop) to read voltage from mulmeter  but I like to get average value of all of 200 reding how can I do that?
    Thanks
    Wee
    Solved!
    Go to Solution.

    Another idea with less programming - take advantage of the "free" array that comes with a Chart - i.e. the  History Data.
    1) Wire your DMM data to a Chart. (You can set the chart to invisible if you don't plan on using it in the GUI).
    2) Set the Chart History Length to 200 (right click on the chart, click on Chart History Length...)
    3) On the block diagram, use the History Data Property Node, wire it to Mean.vi, and you're done.
    Easiest running average ever.
    Message Edited by Broken Arrow on 04-07-2010 11:36 AM
    Richard
    Attachments:
    EasyAvg.jpg ‏8 KB

  • I have 2 questions regarding the iphone 5. 1 How do i get my yahoo mail set up. I tried the setting it up as both a yahoo mail and other mail. 2. I seem to have lost my notes on my iphone 5 but I have them on my ipad. How can I use cloud to sync my notes?

    I have 2 questions regarding the iphone 5. 1 How do i get my yahoo mail set up. I tried the setting it up as both a yahoo mail and other mail. 2. I seem to have lost my notes on my iphone 5 but I have them on my ipad. How can I use cloud to sync my notes?

    I will address your second question.
    First, make sure your iPhone and iPad have absolutely identical Apple IDs.  If they do, use that Apple ID in Settings > iCloud on your iPhone to select the "Notes" option.  Lo and behold, all your iCloud notes should appear on your iPhone.

  • I downloaded pictures onto my iPhone from computer twice by mistake now when i uncheck/sync then check and sync again  i keep getting two lots of pics..how can i get just the one set again? thnx

    I downloaded pictures onto my iPhone from computer twice by mistake now when i uncheck/sync then check and sync again  i keep getting two lots of pics..how can i get just the one set again? thnx

    You're welcome.
    All photos transferred from your computer are stored in the iPhone's Photo Library regardless if you select a single album or folder of photos to be transferred or multiple albums or folders. The photos on the albums or folders of photos include a pointer to the original photos stored in the Photo Library. The photos are not duplicated taking up double the storage space. This way you can view the photos in an album or folder of photos only by selecting the album or folder, or all photos in all albums or folders by selecting Photo Library.
    Makes more sense when transferring multiple albums or folders of photos which cannot be changed when transferring only a single album or folder of photos.
    The same applies with iTunes and music playlists. A song can't be in a playlist unless it is in the main iTunes library. Placing a song in a playlist does not duplicate the song.

  • How to get calendar travel time (set up in Mavericks) to show on iOS 7 calendar?

    I was wondering how to get calendar travel time (set up in Mavericks) to show on iOS 7 calendar? If I change a location in mavericaks it is updated in my iOS 7 calendar, but if I add travel time to an appointment, that does not show up on my iphone. This seems like a big miss for apple if this is the case. I could maybe understand not adding the ability to add travel time in iOS 7, but not being able to see the travel times you set up seems very incomplete. Any ideas or insight?

    Hello Cheer,
    I don't believe the table changed when migrating from Access.  I had two tables before the migration, one was for the SwitchBoard Manager and the other table was for the database table.  I used the Switchboard to navigate to different menus, such
    as the Main Form, Power Form, Server Form, etc.  Let me know if I can provide any other information to help you narrow this down for me.   
    Thank you for your assistance. 
    Thai

  • My time machine backup external hard drive has failed.  I have a newer external drive already connected to my MAC but can't figure out how to get Time Machine to set up on it?

    My time machine backup external hard drive has failed.  I have a newer external drive already connected to my MAC but can't figure out how to get Time Machine to set up on it

    http://pondini.org/TM/21.html

  • How to get average stock in the inventory management cube?

    Dear all,
    I need to get average stock for a month.
    For example: stock on May 1st is 30kg,  stock on May 2nd is 20kg,etc. I need to add these everyday stock together and divided by the days of the month.
    Now I have a non-cumulative key figure with inflow and outflow for stock. Is any way I can do this without bringing very bad performance?
    Regards,
    Bolun

    cOULD YOU PLEASE EXPLAIN ME HOW DID YOU SOLVE YOUR PROBLEM

  • Can I get a replacement iphone set or servicing in Hong Kong for my iphone which is purchased in Singapore?

    Can I get a replacement iphone set or servicing in Hong Kong for my iphone which is purchased in Singapore?

    Hello Hokk,
    After reviewing your post, I have located an article that can help in this situation. It contains helpful information about iPhone service options in various countries:
    Apple - Support - Service Answer Center
    Thank you for contributing to Apple Support Communities.
    Cheers,
    BobbyD

  • TS4003 everything else works on my iPhone in iCloud but when I try to connect to iCloud on safari I get the page ICloud set up iCloud on this device etc. What's up?

    everything else works on my iPhone in iCloud but when I try to connect to iCloud on safari I get the page ICloud set up iCloud on this device etc. What's up?

    You cannot connect to iCloud.com from an iOS device, you can only connect from a computer. You can access any of the data in your iCloud account from the appropriate apps on your device (mail, contacts, calendars etc)

  • I just updated my iphone to ios7 and I keep getting stuck at the 'Set up your iPhone' screen. I click 'Restore from Itunes Backup', but it only ends up restarting after restoring and fails to get past the 'Set up your iPhone' screen. Any ideas?

    I just updated my iphone to ios7 and I keep getting stuck at the 'Set up your iPhone' screen. I click 'Restore from Itunes Backup', but it only ends up restarting after restoring and fails to get past the 'Set up your iPhone' screen. Any ideas?

    Normally, I would suggest restoring the iPad and uninstall and reinstall iTunes but you have done both of those things - more times than you ever imagined!
    Have you thought about turning auto syncing off?
    Without connecting your iPad to your laptop, start iTunes. Click on Edit. Click on Preferences. Click on Devices. Check the box next to "Prevent your iPod etc. from automatically syncing." Click OK.
    If you do this you can backup the iPad right away before it syncs. You may want to go into all of the iTunes tabs and just make sure that all of the current content on the iPad is selected to sync before you actually do sync.
    This doesn't solve the problem, but it would prevent the automatic sync and erasing content. Hopefully, in the next few days- when iOS 5 is released - you will also be relieved of this weird iPad behavior - since the iOS devices are supposed to become PC free.
    BTW - and this is no excuse for what you are experiencing, but I have found that some of the game apps that I had on my iPad turned out to be quite troublesome and after I removed them, my problems went away. I know that is almost sacrilege with regard to the Angry Birds addiction .... But I'm just saying ...

  • How do i get rid of the 'set up new email' text on...

    how do i get rid of the 'set up new email' text on the screen ?
    Thanks 

    Menu -> Tools -> Settings -> General -> Personalisation -> Home Screen -> Mode settings -> Home Screen applications -> Enabled applications.
    Remember that Home Screen must be set to Active.

  • When installing Adobe Captivate I get msg: unable to set-up control panel

    When installing Adobe Captivate I get msg: unable to set-up control panel..Does anyone know how to resolve?

    Hi,
    It seems that Captivate is not downloaded completely. Only one file is downloaded(i.e. .exe) , .7z file is missing.  You can follow the below instructions to download Captivate 7 via direct links.
    In order to download Adobe Captivate 7.0 Windows English, open the link mentioned below and sign in with your Adobe ID and password.
    https://www.adobe.com/cfusion/tdrc/index.cfm?product=captivate
    Once you sign In with your Adobe Id and password, you will be redirected to Adobe Captivate 7.0 download page, Do not click on download. Kindly stay on that page and paste the below two links on the Trail Page Address Bar  one by one and save the files on your system at same location:
    http://trials3.adobe.com/AdobeProducts/CPTV/7/win32/Captivate_7_LS21.7z
    http://trials3.adobe.com/AdobeProducts/CPTV/7/win32/Captivate_7_LS21.exe
    When both the files finish downloading, then run the second file (.exe) which will start extracting the first file (.7z) and will start installing Adobe Captivate 7.0 on your computer.
    Regards,
    Mayank

  • When i try to sign in itunes tells me my apple id haw not been used before and to review account but get directed to a set up apple id page.  any ideas why please

    when i try to sign in itunes tells me my apple id has not been used before and to review account but get directed to a set up apple id page.  any ideas why please

    Could it be that you are using your account on more than 10 devices? Or that more than 10 devices are still connected to your account?
    "iTunes Match requires iOS 5.0.1 or later on iPhone 3GS or later, iPod touch (3rd generation or later), iPad, or iPad mini, or a Mac or PC with iTunes 10.5.1 or later. Limit 25,000 songs. iTunes purchases do not count against limit. Access to some services is limited to 10 devices."

  • Keep getting error message "registry setting used by itunes drivers for importing

    Keep getting error message "registry setting used by itunes drivers for importing and burning cds & dvds are missing", this can happen as a result of installing other cd burning software".  The only software on my computer is original cd-dvd on my hp portable with Vista.  My computer now recognized itouch as a camera. Ive uninstalled and reinstalled itunes, nothing changes.

    I'd start with the following document, with one modification. At step 12 after typing GEARAspiWDM press the Enter/Return key once prior to clicking OK. (Pressing Return adds a carriage return in the field and is important.)
    iTunes for Windows: "Registry settings" warning when opening iTunes

Maybe you are looking for

  • HT201302 how can i delete the photo library album from my iphone

    I have an Iphone 5 and since yesterday appeared the photo library album yes i have tryed settings, itunes and iphotos it just won't go  WHAT SHOULD I DO? btw I have a mac book pro so if you could explain the process un mac version I'll be thankfull

  • Error when inserting into table - Undefined Variable

    DB = Oracle 10.2.0.1 WEBSERV = Apache 2.0.55 LANG = PHP5 I have created (or more accurately, copied) a php script to insert data into one of my database tables when I press submit. The code is as follows (my connect string works fine and its included

  • Creating a transition (exploding text?)

    Hi A novice here. I am working on my first banner ad, and I've hit a snag. What I want to achieve is an exploding text effect, though I may have bitten off more than I can chew the way I have done it so far. I started the first frame with a bit of te

  • AUTOMATIC CREATION OF REWORK ORDER

    Hi Could any solve my problem? Basically i am working in pipe manufacturing unit where we follow discrete manufacturing. I have some pipes that been rejected from certain operation and sent for reworking.Now, i want that "A rework order should be cre

  • Smart question

    We all know that TalkTalk have joined BTs fibre network and offer the new 80 download and 20 upload well if I went with TalkTalks deal and have bt home hub 3.0 it would be much cheaper than if I was to go with BTs deal the same one 80 download and 20