Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2006, 2:48 AM   #1
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Problem with an ArrayList

I'm using an Array list to hold a bunch of struct items, but I can't seem to get an insertion going.

struct FullItem
    {
        public String name;
        public int code;
        public int quantity;
        public double price;
        public double weight;
    }

. . .

private ArrayList Purchase = new ArrayList();

. . .

FullItem FullPurchase;
FullPurchase.code = purchase.Code;
FullPurchase.name = purchase.Name;
FullPurchase.price = purchase.Price;

if (purchase.ByWeight == true)
{
      FullPurchase.weight = 100 / 1000;  // add wieght input
      FullPurchase.price = FullPurchase.weight * FullPurchase.price;
}
            
      FullPurchase.quantity = 1; // add something for getting Q numbers

      Purchase.Add(FullPurchase);  //----this line has the error-------

. . .

Oddly enough, I inserted a different sturct item into a different ArrayList, with no problem, and I can clearly access members of FullPurchase, but the add line gives me the following error, wherever I put it:

Error	1	Use of unassigned local variable 'FullPurchase'

Suggestions?
Twilight is offline   Reply With Quote
Old Apr 25th, 2006, 3:59 AM   #2
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 4 Kaja Fumei is on a distinguished road
Even though struct's are stored on the stack, they still need to be allocated and initialized with a call to new:
FullItem FullPurchase = new FullItem();

I'm surprised the errors didnt start on this line:
FullPurchase.code = purchase.Code;
Kaja Fumei is offline   Reply With Quote
Old Apr 25th, 2006, 2:15 PM   #3
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
Yeah, that did it. But It surprises me that I have another instance of this in a different program where I didn't use new and it worked fine
Twilight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC