CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2008
    Posts
    26

    Requesting Stock numbers

    I want to write a program that asks for a stocknumber and when it gets my stock number it will bring up the name of the product, can I do this in a console application, any tips folks. I was planning on creating a separate class.

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Requesting Stock numbers

    Yes, you could write this in a console. And you could probably have several separate classes.

    Were do you want to get the data? Some hard-coded structure? Some file on disk?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Oct 2008
    Posts
    26

    Re: Requesting Stock numbers

    can I not call the data from a class, I was comptiplating taking it from a file on my computer but I want to try taking it from a class.

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: Requesting Stock numbers

    Hi,

    there is just a simple way:

    - Create a new class which loads the data from any file
    and stores into some internal public members, like strings, ints and so one

    - Create an instance of this class in your main and call your class' method to
    load the data and access the data immediately through this class. This works
    if the class members are public.

    Few would suggest do have get/set stuff, but I don't like them much ;-)

  5. #5
    Join Date
    Oct 2008
    Posts
    26

    Re: Requesting Stock numbers

    Quote Originally Posted by MNovy
    Hi,

    there is just a simple way:

    - Create a new class which loads the data from any file
    and stores into some internal public members, like strings, ints and so one

    - Create an instance of this class in your main and call your class' method to
    load the data and access the data immediately through this class. This works
    if the class members are public.

    Few would suggest do have get/set stuff, but I don't like them much ;-)
    any examples on loading the data from any file

  6. #6
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Requesting Stock numbers

    Quote Originally Posted by johnboy14
    any examples on loading the data from any file
    Take a look at the FileStream and StreamReader classes
    It's not a bug, it's a feature!

  7. #7
    Join Date
    Oct 2008
    Posts
    26

    Re: Requesting Stock numbers

    can you read from any file type, word, excel or notepad. Would it be easier to write all the current information in one class for the others to read from. I don't quite understand those classes above.

    What I want is to give the stocknumber and then get the name of the product off the list, I can only think of identifying them through a class at the moment.
    Last edited by johnboy14; October 31st, 2008 at 10:03 AM.

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Requesting Stock numbers

    Quote Originally Posted by MNovy
    Few would suggest do have get/set stuff, but I don't like them much ;-)
    Exposing (data) Fields directly is a bad practice. If places hard limits on the ability to implement techniques such as agressive/lazy evaluation. Additionally if you later have to change a field to a property, you run the risk of breaking existing code.

    Unless you have (the very very rare condition) of having measured a property to introduce overhead that violdates a documented performance specification, there is NO reason to ever have data as anything other than private.

    Also remember that with the latest versions of C#, you can use properties with anonymous backing fields, so there is even less reason.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  9. #9
    Join Date
    Oct 2008
    Posts
    26

    Re: Requesting Stock numbers

    What about the DataSet Feature in visual c#.

  10. #10
    Join Date
    Oct 2008
    Posts
    51

    Re: Requesting Stock numbers

    Quote Originally Posted by johnboy14
    What about the DataSet Feature in visual c#.
    This is my suggestion as well.

    The DataTable Class allows you to crate a table that could represent you data and has a functions for saving it as an XML file and populating it from a previously saved XML table. It even has functions to search the table.

    This seems like it is exactly what you are looking for.

  11. #11
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Requesting Stock numbers

    Quote Originally Posted by ifdef
    This is my suggestion as well.

    The DataTable Class allows you to crate a table that could represent you data and has a functions for saving it as an XML file and populating it from a previously saved XML table. It even has functions to search the table.

    This seems like it is exactly what you are looking for.
    A DAtaSEt would certainly be a "quick and easy" solution, but it may be "heavy" (especially is DataTable.Select("...") is used!!!!!).

    An alternative would be LINQ to XML....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

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

Featured