C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 30th, 2013, 01:28 PM
bensheard bensheard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 bensheard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 46 sec
Reputation Power: 0
Help with Visual C# structures

Hi

I'm using Microsoft Visual C# 2010, and I'm very new to this (although I've had lots of previous experience in other languages).

I may be going around this the complete wrong way, so any advice would be much appreciated.

I'm trying to design a watering system computer: It is made up of different systems, each system comprised of 14 days, and each day comprised of 10 cycles, and each cycle has the properties hour, minute and duration.

I thought the best way to go about working with all this data would be to define structures for a system, day and cycle. At the moment I have this:

Code:
namespace Water_System_Computer
{
    struct WaterSystem
    {
        public WaterDay[] WaterDays;

        public WaterSystem(byte SystemIndex)
        {

            WaterDays = new WaterDay[14];

        }
        
    }

    struct WaterDay
    {
        public WaterCycle[] WaterCycles;

        public WaterDay(byte DayIndex = 0)
        {
            WaterCycles = new WaterCycle[10];
        }

    }

    struct WaterCycle
    {
        public byte hour;
        public byte minute;
        public byte duration;

        public WaterCycle(byte Duration = 0)
        {

            hour = 0;
            minute = 0;
            duration = 0;

        }
    }
}


In my main class I then have:

Code:
 public partial class MainWindow : Form
    {

        private WaterSystem[] WaterSystems = new WaterSystem[16];

...


In a particular method I then want to set some dummy data into a water cycle, and I have:

Code:
WaterSystems[0].WaterDays[0].WaterCycles[0].hour = 12;
            WaterSystems[0].WaterDays[0].WaterCycles[0].minute = 37;
            WaterSystems[0].WaterDays[0].WaterCycles[0].duration = 20;


But this is where I'm getting errors. I'm guessing I've probably gone wrong fundamentally somewhere, but the error I'm getting at this point is NullErrorException: Object reference not set to an instance of an object.

And help or pointers would be greatly appreciated.

Reply With Quote
  #2  
Old January 30th, 2013, 03:42 PM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 120 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 19 h 7 m 57 sec
Reputation Power: 44
You're not allocating enough memory:

Code:
            WaterSystems[0].WaterDays = new WaterDay[16];
            WaterSystems[0].WaterDays[0].WaterCycles = new WaterCycle[16];
            WaterSystems[0].WaterDays[0].WaterCycles[0].hour = 12;
            WaterSystems[0].WaterDays[0].WaterCycles[0].minute = 37;
            WaterSystems[0].WaterDays[0].WaterCycles[0].duration = 20;

Reply With Quote
  #3  
Old January 31st, 2013, 01:38 AM
bensheard bensheard is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 bensheard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 46 sec
Reputation Power: 0
Thanks, that's sorted it out!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help with Visual C# structures

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap