+ Reply to Thread
Results 1 to 16 of 16

Thread: Programming help     submit to reddit submit to twitter

  1. #1
    New Spam Forum
    Join Date
    Jun 2009
    Posts
    162
    BG Level
    3
    FFXI Server
    Bahamut

    Programming help

    I am trying to code this program with VB script, and for the life of me I cannot figure out how to properly code half of it.

    The program instruction are as follows:
    You need to write a program for a wedding planner. They wish to create a gift registry for each couple. They want the gifts broken down by the whether the gift giver is on the bride side or groom side. They also know that common gifts (toasters, silverware, and stemware) tend to be repeated so they want those gifts listed and have the name of the gift giver under them. The following is an example of the output they wish. The following output was created using the following input: Tom, Groom side, Toaster; Bill, Groom side, silverware; Bob, Groom side, stemware; Steve, Groom side, Lexus; Jill, Bride side, toaster; Suzy, Bride side, silverware; Pat, Bride side, stemware; Karen, Bride side, horse.

    Groom side:
    1. Tom: toaster
    2. Bill: silverware
    3. Bob: stemware
    4. Steve: Lexus

    Bride side:
    1. Jill: toaster
    2. Suzy: silverware
    3. Pat: stemware
    4. Karen: horse

    Multiple toasters by:
    Tom
    Jill

    Multiple silverware by:
    Bill
    Suzy

    Multiple stemware by:
    Bob
    Pat
    I already know how to code the first half to display who got what gift, but I am stuck on the second half where the program somehow identifies who got multiple of a gift.

    I am trying to get this work in a variety of ways, Case Selection, if-then-else statements, I need to do a loop for the first half so I know what to do there. I can't seem to understand how to get the program to accumulate multiples of items received.

    Any help you guys can provide would of great help.

    Thx in advance

  2. #2
    Chram
    Join Date
    Nov 2005
    Posts
    2,992
    BG Level
    7
    FFXIV Character
    Coren Cypher
    FFXIV Server
    Sargatanas

    Couldn't you just populate a few arrays with names as you loop through the first time? If you're only after those 3, you should be able to do a fairly simple if/then/else statement. Even better, you should be able to use arrays for everything... Just test each set of data for both sets of criteria: groom/bride, toaster/silverware/stemware.

  3. #3
    New Spam Forum
    Join Date
    Jun 2009
    Posts
    162
    BG Level
    3
    FFXI Server
    Bahamut

    never learned about arrays before, I am sorta new to programming and the class I take is simply introductory. Is there a good place to learn about them other than scouring google for it? Will these arrays still be capable of identifying who had multiple gifts?

  4. #4
    The Wang
    Join Date
    Jun 2006
    Posts
    1,345
    BG Level
    6
    FFXIV Character
    Furt Wangler
    FFXIV Server
    Coeurl
    FFXI Server
    Sylph

    Basically, an array is a way to store a list of things.

    The only thing with arrays, is you have to know the size of that list before you instantiate the array. Think of it as like making a bookshelf for books. You can only fit so many books, and you'll know how many books it can hold upon building it.
    Secondly, the array can only hold one type, say ints or in this case you would want strings.


    For example,
    String strArray[] = new String[1];

    Will make an array containing the type String, and in this case it will hold 1 strings.
    Just like making an int - int number = 4;

    You want to declare the type of the array, the name(with those brackets, to indicate it's an array), and it = a new type array with x number

    to add to that array, you could type strArray[0] = "John";
    that adds John to the first spot of the array. Indexes of arrays start at 0.

    (If you don't know what Indexes are, they are the way to tell the array, i want to look at THIS spot in the array, kind of like an address. Indexes always start at 0 and go up from there. It's important to realize that the size of the array, if it was 1, has only 1 spot, but that spot is considered an index of "0".


    For this case, you don't know what the size of people input will be at first unless you finish reading the lines.
    You could technically give it some arbitrarily high number limit (bad idea), or if you have all of the people loaded in already you would know the max number of people and could then make the array that size.

    I would suggest using an ArrayList, which is a data structure provided by Java. Basically it acts as an array, but you can add as many elements to it and it will keep resizing itself.

    You can create one of these by saying ArrayList nameOfList = new ArrayList<type>(); In this case the type would be String.

    you can then say nameOflist.add(name); to add someones name to that list.

    Have you been taught about for loops yet? You would use loops to go over these arrays or lists for each type of gift and print it out.

  5. #5
    New Spam Forum
    Join Date
    Jun 2009
    Posts
    162
    BG Level
    3
    FFXI Server
    Bahamut

    Yea, I have been taught about for loops but have no idea how to implement them to work with an array. Also, I am using VBscript, that is the language we need to use, and we have to use a program called HTML-kit to write the code. I am not sure if I will be allowed to use java, unless these arraylist can be used with VBscript.

  6. #6
    Black Belt
    Join Date
    Aug 2005
    Posts
    5,907
    BG Level
    8
    FFXI Server
    Quetzalcoatl

    Don't see how that would be very hard. Like Furt says, easiest way would be to insert them in to an array, then have the program read the array and compare the entries to see if there's any doubles of an entry, and then list them by writing out everything on said array number.

    As for making a loop work with an array, what exactly do you have a problem with there? It'd not all that different from doing a loop of anything else. You want to write a bit of code that reads the entries in it. To not get too advanced (as I'm guessing it's a basic course), you could make it so that every time it finds, say, "silverware", it adds the array entry in to a separate array you named anything you like. If the number of entries in the variable is 2, then the program lists the entries. Between each "search" - that is, if it stops searching the array for silverware and starts looking for stemware - it resets the array to 0.

    there's lots of ways to go about it, some harder, some easier. The above method would probably be one of the easier, but it's not the best, cleanest nor most effective.

  7. #7
    Sea Torques
    Join Date
    Oct 2006
    Posts
    566
    BG Level
    5
    FFXI Server
    Sylph

    ArrayList is part of the .NET framework, so you could use it in ASP.NET, but I don't think VBScript supports it. In VBScript:

    The following code creates an array.
    Code:
    Dim simpleArray()
    This clears the array and resizes it to have a size of 10 (note: I assume it clears the array, but I don't use VBScript)
    Code:
    ReDim simpleArray(10)
    This doesn't clear the array an resizes it to have a size of 15 (this means that the first ten elements are still there, with an additional five empty indices becoming available on the end).
    Code:
    ReDim Preserve simpleArray(15)
    If you want to iterate through an array, something like the following should suffice:
    Code:
    For i = 0 to UBound(simpleArray) 
    // do things
    Next
    (UBound, if you are unaware, is the UpperBound of the array. It this case, we are using it to get the size of the array. LBound would get you the lowest possible index, which would be 0, in this case).

    I would suggest using that information to attempt to find your own solution to the problem. Below, I've listed my thought process as I walked through the issue. Since I don't use VBScript and I'm not sure what you've learned how to do so far, the following walk-through may be useless to you. This is how I would complete the problem, going off the information that you have given.

    Since it looks like you're getting your data from a comma delimited string with semi-colons marking the end of a row of data, my first step would be to put this data into a more structured format. Since we know that each string is separated by a semi-colon, we can easily split the string on the semi-colons to create an array of strings, with each string containing a single row of our data.

    We also know that each row of data contains three pieces of information, separated by a comma (Name, Side, Gift). At this point, I would create a structure (edit: VBScript lacks structures, so it would just be a class) with three data members (Name, Side, Gift). The constructor for this class would accept a single comma delimited string as a parameter. The constructor would split the string on commas and assign the strings to the proper class member.

    Now that I have a class that takes a comma-delimited string as a parameter, I would create an array of this class with a size equal to the size of the first string array I got when splitting on the semi-colons (if we assume all data is received at the same time, we know the length of our array; if we can't assume that, it is possible to add code to handle resizing the array). I would loop through the string array, creating a new instance of my class with the string passed as the parameter.

    At this point, I would create a Dictionary. A Dictionary is a KeyValue pairing. A key is a unique identifier that can only exist once in the dictionary. A value is a piece of data that is associated with that key. Once you've created a Dictionary, you can edit the loop that creates your class to include some additional Dictionary code. Using the Gift Name as the key, you can check if the key exists in the Dictionary. If it doesn't, you would add it to the Dictionary and set the value of Item to be something (I say something because there are several routes you could take, each of them being something that you would've done to this point. The simplest and quickest way that comes to mind would be to set Item to equal a string array with the first value being the name of gift-giver). If the key exists in the Dictionary, it means someone has already given that gift. In this case, you would need to resize the array (preserving previous contents) and add the name of the gift-giver.

    At this point, all you need to do is loop through the Array and Dictionary, printing the information that you need.

    Again, I should stress that I don't use VBScript, so I'm not certain how well this theoryProgram would run or how well it suits the issue you're working on.

  8. #8

    Why are you using VB Script?




    edit: GOD WHY is an introductory course using VB Script. Shit's so bad.... Makes programming more confusing for beginners.

  9. #9
    Chram
    Join Date
    Aug 2007
    Posts
    2,699
    BG Level
    7
    FFXIV Character
    Nours Sruon
    FFXIV Server
    Moogle
    FFXI Server
    Fenrir

    Quote Originally Posted by Zhais View Post
    Why are you using VB Script?




    edit: GOD WHY is an introductory course using VB Script. Shit's so bad.... Makes programming more confusing for beginners.
    My thoughts.

  10. #10
    Banned.

    Join Date
    Jul 2005
    Posts
    5,836
    BG Level
    8
    FFXI Server
    Sylph
    WoW Realm
    Arthas

    I think you should figure it out on your own. You wont get anything out of it by cheating. But if you want the answer, I included a simple version in the spoiler.

    Spoiler: show

    Dunno vb script, but this is a way to do it pretty easily; Didn't test this at all so not sure if it works, the logic should, but I'm not sure about the code. Either way, it'll get you on the right path hopefully.

    Outside the main class:
    Code:
    Class Gift
    {
      Public String Name;
      Public String Side;
      Public String Gift;
    }
    In the main class

    Code:
    List<Gift> GiftList = new List<Gift>();
    
    //I'll leave it to you to get the name, side, and gift from the user.
    private void addGift(String name, String side, String gift)
    {
       Gift newGift = new Gift()
       newGift.Name = name;
       newGift.Side = side;
       newGift.Gift = gift;
    
      GiftList.Items.Add(newGift);
    }
    
    private void searchName(String Name)
    {
    
        foreach(Gift item in GiftList)
        { 
           if(Name != item.Name) continue;
    
            //Output code here
            MessageBox.Show(item.Name +", " + item.Side + ", " +item.Gift")
        }
    }
    
    private void searchGifts(String Name)
    {
      
        foreach(Gift item in GiftList)
        { 
           if(Name != item.Gift) continue;
    
            //Output code here
            MessageBox.Show(item.Name +", " + item.Side + ", " +item.Gift")
        }
    }
    
    etc etc etc.
    All you have to do is in the search loop, include another param named Side, for example. If (Side != item.Side) continue; under the one thats already there. Make it a conditional param and search and you can do it all in one function. Super simple broski.
    Hope I understood everything right and hope this helps you.

  11. #11

    there are no classes in vbscript

    Bloodfire, send me a PM if you still need help. Not sure where you're at with what other's have told you. I work with VB Script unfortunately, so I can help you out.

  12. #12
    Sea Torques
    Join Date
    Oct 2006
    Posts
    566
    BG Level
    5
    FFXI Server
    Sylph

    Quote Originally Posted by Zhais View Post
    there are no classes in vbscript
    Uh, VBScript has support for classes. The following code will create a class with three public members.

    Code:
    Class SampleClass
        Public Name
        Public Side
        Public Gift
    End Class
    To create a new instance of the class:

    Code:
    Dim example
    Set example = New SampleClass
    Then you can set the members as you would set anything else:

    Code:
    example.Name = "Some Name"

  13. #13
    Banned.

    Join Date
    Jul 2005
    Posts
    5,836
    BG Level
    8
    FFXI Server
    Sylph
    WoW Realm
    Arthas

    Quote Originally Posted by Zhais View Post
    there are no classes in vbscript
    How do you suppose that works in a class based object oriented language? Hmm.

  14. #14

    I take that back!

    That is now to say, I've never SEEN anyone use custom classes ever in vb script at my work. It's that sad

    I do all my new development in .NET, trying to avoid classic as much as possible.


    edit: I guess I really should have been more specific in previous post. Mainly was referring to custom classes. Of course VB is object-oriented and can instantiate VBS objects/COM objects etc. Just never seen custom classes used personally. Can't tell if they're even available in any form outside of the current file. No true object inheritance and such, but anyways. But yes, I eat my words and you can do custom classes in VBS.

  15. #15
    Yoshi P
    Join Date
    Aug 2006
    Posts
    5,141
    BG Level
    8
    FFXIV Character
    Dead Gye
    FFXIV Server
    Lamia
    FFXI Server
    Ragnarok

    Coding in VB is like cumming in someone's ear. Sure, it's technically sex.. but why would you ever do it?

  16. #16
    Smells like Onions
    Join Date
    Apr 2011
    Posts
    1
    BG Level
    0

    Bloodfire could you post on here the first part of your vbscript, the part that displays who got what gift so i can look at that and try and help you?

Similar Threads

  1. Programming help
    By Lost in forum Tech
    Replies: 13
    Last Post: 2012-02-28, 09:28
  2. VB.Net Programming Help
    By Datonare in forum Tech
    Replies: 10
    Last Post: 2012-02-25, 00:17
  3. Java program Help: KI tracker
    By Skie in forum Tech
    Replies: 19
    Last Post: 2011-04-08, 09:31
  4. Beginner Programming Help Thread
    By Callisto in forum Tech
    Replies: 13
    Last Post: 2011-03-04, 18:24
  5. Replies: 8
    Last Post: 2010-02-20, 01:21
  6. Help finding a program
    By Darunia in forum Tech
    Replies: 4
    Last Post: 2007-07-10, 22:03