|
-
Nov 14th, 2010, 03:49 PM
#1
Thread Starter
New Member
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!
-
Nov 14th, 2010, 04:05 PM
#2
Lively Member
Re: Confusing code to program? =/
Sorry, this is a bit sloppy but its a general direction
lll Code:
Dim Article As New Specialized.StringCollection
Dim Noun As New Specialized.StringCollection
Dim UsedOrders As New Specialized.StringCollection
'fill up those string collections (and make new ones) for your words
Article.add ("the")
Article.add ("a")
Noun.Add("baby")
Noun.Add("skunk")
Public Function GenerateSentence() As String
Dim TMPWORD As String
GenerateSentence= Article(Randomnumber(Article.Count)) & " "
' loop until the sentence so far does not contain the
' TMPWORD (the temporarily grabbed up word)
Do Until GeneratedSentence.Contains(TMPWORD)=False
TMPWORD=Noun(Randomnumber(Noun.Count))
Loop
GenerateSentence & =TMPWORD & " "
' now repeat that idea for the next parts
Do Until GeneratedSentence.Contains(TMPWORD)=False
TMPWORD=Noun(Randomnumber(Noun.Count))
Loop
GenerateSentence & =TMPWORD & " "
Return GenerateSentence
End Function
' 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)
Public Function RandomNumber(ByVal Highestnumber)
'code to generate random number with cieling highest number
End Function
-
Nov 14th, 2010, 04:34 PM
#3
Re: Confusing code to program? =/
@BD
the Specialized.StringCollection isn't generally used outside of my.settings...
try a list(of string) instead
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 14th, 2010, 05:07 PM
#4
Frenzied Member
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.
-
Nov 14th, 2010, 07:22 PM
#5
Re: Confusing code to program? =/
 Originally Posted by 03myersd
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.
-
Nov 14th, 2010, 10:24 PM
#6
Thread Starter
New Member
Re: Confusing code to program? =/
I have to use Visual Basic :/
-
Nov 14th, 2010, 10:30 PM
#7
Re: Confusing code to program? =/
 Originally Posted by appleallie
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.
-
Nov 15th, 2010, 12:00 AM
#8
Thread Starter
New Member
Re: Confusing code to program? =/
 Originally Posted by jmcilhinney
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.
-
Nov 15th, 2010, 12:32 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|