Help with ArrayList as returned argument

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Help with ArrayList as returned argument

 
0
  #1
Dec 1st, 2007
I have this ArrayList that consist of list of structure and I would like to use the content of the ArrayList as the return type for the function bellow. Can anyone help please.

  1. public struct DeviceSchedules
  2. {
  3. public string StartDate;
  4. public string EndDate;
  5. public string Interval;
  6. public string DeviceTimeZone;
  7. public string GLRID;
  8. public string TrackUID;
  9. }
  10.  
  11. [WebMethod()]
  12. public DeviceSchedules theSchedules()
  13. {
  14. ArrayList ZoneArray = new ArrayList();
  15. ZoneArray.Add("PST");
  16. ZoneArray.Add("MST");
  17. ZoneArray.Add("CST");
  18. ZoneArray.Add("EST");
  19.  
  20. DeviceSchedules Schedules = new DeviceSchedules();
  21. ArrayList GroupSchedule = new ArrayList();
  22.  
  23. Int16 Zone = 1;
  24. DateTime Begining = DateTime.Now.AddHours(Zone);
  25. DateTime End = DateTime.Now.AddHours(Zone);
  26. //int Zone = 3;
  27. Int32 TrackID = 9999;
  28. Int32 ScheduleID = 400;
  29. int Frequency = 40;
  30. for (int index = 0; index <= 5; index++)
  31. {
  32. Schedules.StartDate = Convert.ToString(Begining);
  33. Schedules.EndDate = Convert.ToString(End);
  34. Schedules.Interval = Convert.ToString(Frequency);
  35. Schedules.DeviceTimeZone = Convert.ToString(ZoneArray[Zone]);
  36. Schedules.GLRID = Convert.ToString(ScheduleID);
  37. Schedules.TrackUID = Convert.ToString(TrackID);
  38. GroupSchedule.Add(Schedules);
  39. }
  40. return (GroupSchedule);
  41. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Help with ArrayList as returned argument

 
0
  #2
Dec 2nd, 2007
you have to declare the function as an array/string. Something like this would be:

public string[] functionName()
{
}

enjoy
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: Help with ArrayList as returned argument

 
0
  #3
Dec 3rd, 2007
The suggested implementation did not work. I have also tried some other method to read the list and they don't work either.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Help with ArrayList as returned argument

 
0
  #4
Dec 3rd, 2007
have you tried to see if the array contains information?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: Help with ArrayList as returned argument

 
0
  #5
Dec 3rd, 2007
yes the array have the information. I've also test for the size of the array.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: Help with ArrayList as returned argument

 
0
  #6
Dec 3rd, 2007
The correct implementation to the above question is as follow
  1. public struct DeviceSchedules
  2. {
  3. public string StartDate;
  4. public string EndDate;
  5. public string Interval;
  6. public string DeviceTimeZone;
  7. public string GLRID;
  8. public string TrackUID;
  9. }
  10.  
  11. [WebMethod()]
  12. public DeviceSchedules[] theSchedules()
  13. {
  14. ArrayList ZoneArray = new ArrayList();
  15. ZoneArray.Add("PST");
  16. ZoneArray.Add("MST");
  17. ZoneArray.Add("CST");
  18. ZoneArray.Add("EST");
  19.  
  20. DeviceSchedules Schedules = new DeviceSchedules();
  21. ArrayList GroupSchedule = new ArrayList();
  22.  
  23. Int16 Zone = 1;
  24. DateTime Begining = DateTime.Now.AddHours(Zone);
  25. DateTime End = DateTime.Now.AddHours(Zone);
  26. //int Zone = 3;
  27. Int32 TrackID = 9999;
  28. Int32 ScheduleID = 400;
  29. int Frequency = 40;
  30. for (int index = 0; index <= 5; index++)
  31. {
  32. Schedules.StartDate = Convert.ToString(Begining);
  33. Schedules.EndDate = Convert.ToString(End);
  34. Schedules.Interval = Convert.ToString(Frequency);
  35. Schedules.DeviceTimeZone = Convert.ToString(ZoneArray[Zone]);
  36. Schedules.GLRID = Convert.ToString(ScheduleID);
  37. Schedules.TrackUID = Convert.ToString(TrackID);
  38. GroupSchedule.Add(Schedules);
  39. }
  40. return ((DeviceSchedules[])GroupSchedule.ToArray(typeOf(DeviceSchedule)));
  41. }

This is kind of "?!@#$%%^&*(@"...
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Help with ArrayList as returned argument

 
0
  #7
Dec 4th, 2007
yeah.. that's odd. but if it works.. however, i am surprised that my solution didn't work for you! I mean, you declared at the start, instead of formatting at the end. Made sense to me.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: Help with ArrayList as returned argument

 
0
  #8
Dec 4th, 2007
I am still trying to understand why the latter works. I agree with your suggestion and it should have worked; But I guessed there is a special convention about ArrayList we must understand. Information like that doesn't exist in books. I had to dig through the MSDN to get the aforementioned implementation.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC