vb random sentance generator

Terabojin

Active member
Joined
Mar 4, 2012
Messages
33
Programming Experience
Beginner
Hello,

I am working on an application that once clicked will produce 10 random sentances. This is what I have so far, but I'm not sure where to go from here.

    ' String arrays for articles, nouns, verbs and prepositions
    Dim articles As String() = {"the", "a", "one", "some", "any"}
    Dim nouns As String() = {"boy", "girl", "dog", "town", "car"}
    Dim verbs As String() = {"drove", "jumped", "ran", "walked", "skipped"}
    Dim prepositions As String() = {"to", "from", "over", "under", "on"}
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rndm As Random = New Random
        Dim Sentence As String = ""
        Dim myCounter As Integer
        Dim Sentences = {articles, nouns, verbs, prepositions}
        For myCounter = 0 To 9
        Next
        Dim randomArticle = articles(rndm.Next(0, articles.Count))
        Dim randomNoun = nouns(rndm.Next(0, articles.Count))
        Dim randomVerb = verbs(rndm.Next(0, verbs.Count))
        Dim randomPrep = prepositions(rndm.Next(0, prepositions.Count))
 
    End Sub
End Class


Please help? I know that I need it to be output, but I'm really struggling with this. I'm not sure what to do.
 
Last edited:
for one thing your for loop doesn't do anything because you have "next" in the wrong place

there needs to be some code between the for myCounter = 0 to 9 and next

InkedGFX
 
Hi,

Just to add a few comments to inkedgfx's note:-

You create a variable array called Sentences using Dim Sentences = {articles, nouns, verbs, prepositions} but in the context of your code this is not necessary and nor do you use it. Other than that and inkedgfx's comment you have got the main components written to make this work.

The thing to do now is decide how to build the random sentence from the random words that you have generated and display them. Think back to your program where you displayed shapes using stars in a control. What did you use and how did you do that?

Hope that helps.

Cheers,

Ian
 
Just to add to what others have said. The Dim keyword takes the default instance. In this case it will be private. If this was a structure it would be public. We should always declare it's modifier.

VB.NET:
Private ReadOnly m_articles As String() = {"the", "a", "one", "some", "any"}
    Private ReadOnly m_nouns As String() = {"boy", "girl", "dog", "town", "car"}
    Private ReadOnly m_verbs As String() = {"drove", "jumped", "ran", "walked", "skipped"}
    Private ReadOnly m_prepositions As String() = {"to", "from", "over", "under", "on"}

Also create a single Random object and call Next. This should not be declared inside the button.
 
Back
Top