dcsimg
Results 1 to 3 of 3

Thread: Confusion again with classes :(

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    946

    Confusion again with classes :(

    Hi

    i think i have asked this in one way or another a hundred times, i have basically a hierarchy of objects that im trying to put together and my head goes blank when trying to do it.

    basically i want a presets object/class which stores another 3 levels of objects all inside eachother.

    something like this:-

    Presets
    ---->Dictionary(of String, PresetClass)


    PresetClass
    ---->PresetName
    ---->Dictionary(of String, ActionsClass)

    ActionsClass
    ---->ActionName
    ---->Dictionary(of Integer, ActionClass)

    ActionClass
    ---->ActionToPerform
    ---->OtherActionRelatedStuff
    ---->etc

    I need to be able to select a preset and the form loads all the saved preset data, within that preset data there are lists of actions/jobs to perform that i also need to be able to select and load te relevant data for the next level which is the individual actions that a job is comprised of.

    Preset
    List of jobs
    each job has list of particular actions and settings

    i want it all inside a single class so i can just save it in my.settings as a single object


    im getting confused because im not sure how to access everything on the actions level easily without passing objects everywhere running loops just to get a single string, am i doing this the right way?
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,140

    Re: Confusion again with classes :(

    First of all, don't suffix a class name with class. Do you use StringClass and FormClass from the Framework? No, you use String and Form. Your classes can be Preset, Presets, Action and Actions or whatever else is appropriate but it is a very rare thing that using "Class" as a suffix is appropriate. You would only do that when the rest of the name is a verb or adjective. If it's a noun, as in this case, using a "Class" suffix is absolutely wrong. As for your question, getting the action to perform from a Presets dictionary is a one-liner, e.g.
    Code:
    Dim actionToPerform = myPresets(presetName).Actions(actionName).ActionToPerform
    Maybe I've misinterpreted the hierarchy sightly wrong but it's going to be something like that. It's basically very similar to getting a field value from a DataRow in a DataTable in a DataSet.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    946

    Re: Confusion again with classes :(

    dont worry i just put the suffix here so its obvious its a class,

    so far i have created it like i mentioned in my last post, creating the whole hierarchy of objects seems un-natural as i have to do it all in reverse.

    this is the working code that creates all the objects and stores a single preset with a single job with a single action.

    Code:
    Dim act As New Action(1, "action1", 1, "A:1") 'Last in Hierarchy, stores data for a particular action to perform, ID = Integer, to keep order of actions
    Dim jobb As New Job("job1") 'Stores All Actions the job is comprised of, ID =  String, Key, 
    jobb.AddAction(act) 'Actions need to be added in seperate method
    Dim pres As New Preset("Preset1") 'Stores all jobs related to a preset, jobs need adding in seperate method
    pres.AddJob(jobb.JobName, jobb)
    Dim AllPresets As New JobPresets 'Base variable/Object, which will be saved into settings
    AllPresets.AddPreset(pres.PresetName, pres)
    im just going to test it all out now so i will post back if its working fine.
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width