Results 1 to 2 of 2

Thread: [VS2005] Data Structures

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    [VS2005] Data Structures

    I am having a problem trying to keep track of some Excel Files and Sheet names.
    These excel files and sheets are created dynamically, when a user clicks some buttons is creates the excel file and the sheet. I have been trying to use an arraylist but for some reason it is loosing files. Is there a better structure I can use that can relate File to Sheet and Sheet to File.

    I have thought about a Hashtable for each excel file be the key (since they will always be unique) and value as the sheet name but I need to file name as well.

    Here is the code I am using this far...

    cQueueExcelFiles and cSheets are both arraylist.
    VB Code:
    1. ///<summary>
    2.         /// Gets the next excel file in the queue, returns null if nothing left in queue.
    3.         ///</summary>
    4.         public string XlNextFile
    5.         {
    6.             get
    7.             {
    8.                 string next = null;
    9.  
    10.                 try
    11.                 {
    12.                     next = (String)cQueueExcelFile[this.cQueueExcelFile.Count - 1];
    13.                     cQueueExcelFile.Remove(next);
    14.                 }
    15.                 catch (ArgumentOutOfRangeException)
    16.                 {
    17.                     next = null;
    18.                 }
    19.                 return next;
    20.             }
    21.         }
    22.  
    23.         ///<summary>
    24.         /// Returns the next excel sheet name.
    25.         ///</summary>
    26.         private string XlNextSheet
    27.         {
    28.             get
    29.             {
    30.                 string next = null;
    31.                 try
    32.                 {
    33.                     next = (String)this.cSheets[this.cSheets.Count - 1];
    34.                     cSheets.Remove(next);
    35.                 }
    36.                 catch (ArgumentOutOfRangeException)
    37.                 {
    38.                     next = null;
    39.                 }
    40.                 return next;
    41.             }
    42.         }
    43.  
    44. ///<summary>
    45.         /// Sets the Excel Files waiting to be processed in a Queue.
    46.         ///</summary>
    47.         public string XlQueueFile
    48.         {
    49.             set
    50.             {
    51.  
    52.                 if (this.cQueueExcelFile == null)
    53.                 {
    54.                     cQueueExcelFile = new ArrayList();
    55.                 }
    56.                 this.cQueueExcelFile.Add(value.ToString());
    57.             }
    58.  
    59.         }
    60.         #endregion

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [VS2005] Data Structures

    I really don't see how an ArrayList can "lose" files. Items are only removed when you remove them, so that would imply that you are removing items from one or both of the Arraylists when you shouldn't be.

    Also, I really think methods would be more appropriate than properties, particulary for XLQueueFile. A property is absolutely not appropriate for that, while a case could at least be made for the other two, although getting a property shouldn't change that property, so a method would still be more appropriate for those two as well.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width