Results 1 to 9 of 9

Thread: Confusing code to program? =/

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Unhappy Confusing code to program? =/

    Heya, I'm a beginner user with Visual Basic 8 and am trying to write a specific program but can't even figure out how to start.

    I'm trying to create a program that produces random sentences as output. With five arrays of strings, one each for nouns, adjectives, verbs, prepositions, and articles. Each array should hold several words for that part of speech. Like, the Articles array could hold the strings “the” and “a”; the Nouns array could hold “Martian”, “baby”, “skunk”, “computer”, and “mosquito”; the Prepositions array could hold “around”, “through”, “under”, “over”, and “by”; and so on.

    It's supposed to generate sentences by randomly choosing eight words (randomly generating eight array indices) from these arrays, always constructing sentences by using the parts of speech in the following order: article, adjective, noun, verb, preposition, article, adjective, noun.

    Also, theh code should be properly modularized so that the code to generate each part of speech is not repeated.

    Any help would be much appreciated!

  2. #2
    Lively Member
    Join Date
    Sep 2008
    Posts
    72

    Re: Confusing code to program? =/

    Sorry, this is a bit sloppy but its a general direction

    lll Code:
    1. Dim Article As New Specialized.StringCollection
    2.     Dim Noun As New Specialized.StringCollection
    3.     Dim UsedOrders As New Specialized.StringCollection
    4.    
    5.     'fill up those string collections (and make new ones) for your words
    6.     Article.add ("the")
    7.     Article.add ("a")
    8.     Noun.Add("baby")
    9.     Noun.Add("skunk")
    10.  
    11.     Public Function GenerateSentence() As String
    12.        Dim TMPWORD As String
    13.        GenerateSentence= Article(Randomnumber(Article.Count)) & " "
    14.  
    15.        ' loop until the sentence so far does not contain the
    16.        ' TMPWORD (the temporarily grabbed up word)
    17.        Do Until GeneratedSentence.Contains(TMPWORD)=False
    18.            TMPWORD=Noun(Randomnumber(Noun.Count))
    19.        Loop
    20.        GenerateSentence & =TMPWORD & " "
    21.  
    22.        ' now repeat that idea for the next parts
    23.        Do Until GeneratedSentence.Contains(TMPWORD)=False
    24.            TMPWORD=Noun(Randomnumber(Noun.Count))
    25.        Loop
    26.        GenerateSentence & =TMPWORD & " "
    27.  
    28.       Return GenerateSentence
    29.     End Function
    30.  
    31.     ' this code doesnt work, but out random number generator here, one that takes in the highest number (which is the number of words in your collections)
    32.     Public Function RandomNumber(ByVal Highestnumber)
    33.         'code to generate random number with cieling highest number
    34.     End Function

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Confusing code to program? =/

    @BD

    the Specialized.StringCollection isn't generally used outside of my.settings...
    try a list(of string) instead

  4. #4
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: Confusing code to program? =/

    This probably wont be a helpful answer, and I apologise if that is the case, but an alternative could be to use the Natural Language Toolkit with python? I am currently using it for my univeristy course on language processing and have found it immensly useful for things like this.

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

    Re: Confusing code to program? =/

    Quote Originally Posted by 03myersd View Post
    This probably wont be a helpful answer, and I apologise if that is the case, but an alternative could be to use the Natural Language Toolkit with python? I am currently using it for my univeristy course on language processing and have found it immensly useful for things like this.
    It could be helpful, depending on the circumstances. Sometimes it's a good idea to create libraries using other languages when that language is more suited to a particular task than the one you're using for your app. Creating a library using IronPython would give you access to all that Python can do and then expose that to .NET assemblies. Of course, it means learning Python. Not such a bad thing.
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: Confusing code to program? =/

    I have to use Visual Basic :/

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

    Re: Confusing code to program? =/

    Quote Originally Posted by appleallie View Post
    I have to use Visual Basic :/
    That would suggest that this is homework then. What efforts have you made on your own behalf? Just posting the assignment and asking for help doesn;t really cut it. If you have no idea where to start then you either haven't paid attention in class or you haven't actually thought about the problem. If you have done those things then you should be able to tell us what you think you need to do and, if you are stuck on something, ask about that specifically.
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: Confusing code to program? =/

    Quote Originally Posted by jmcilhinney View Post
    That would suggest that this is homework then. What efforts have you made on your own behalf? Just posting the assignment and asking for help doesn;t really cut it. If you have no idea where to start then you either haven't paid attention in class or you haven't actually thought about the problem. If you have done those things then you should be able to tell us what you think you need to do and, if you are stuck on something, ask about that specifically.

    Yes this is a homework problem, I didn't mean to mislead anyone though? All I understand is that I know I need to make and use an array for this problem but I wouldn't have posted this if I actually did know what to do and just didn't feel like doing it. I know how to make a random generator but I have no idea how to make a loop "pick and choose" from random words from a word pool. My professor doesn't teach us everything, he expects us to find information online. So please don't accuse me of not paying attention in class or being lazy, seeing as this is the first time in a 10 week semester I've been entirely lost in a homework problem, I clearly do in fact pay attention and am just now looking for aid in the class.
    I will probably end up going to professor office hours, but I wanted to see if maybe I could get a head in the right direction first online.

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

    Re: Confusing code to program? =/

    That's fine, but I would suggest not just posting your assignment question and asking for help. We only know what you tell us and if you don't give us any indication that you know anything or have done anything then as far as we know, you don't know anything and you haven't done anything. If you know how to do part of it then tell us that and specify the part(s) that you're having problems with. If you know how to do part of it then do part of it. You don;t have to build a car to make a wheel. Write parts of the code that do a specific job, e.g. get a random element from an array. When you get the rest of the app fleshed out you can then just plug that part in. Do what you can and tell us specifically what you can't. If you don't know specifically what you can't do then you should spend some more time evaluating the problem and breaking it down into parts. No problem is just one problem. It's a combination of smaller problems. Solve each of those and you have inherently solved the whole. The first step is determining what those smaller problems are.
    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