1 Replies - 178 Views - Last Post: 23 August 2019 - 08:36 PM Rate Topic: -----

#1 DWWang265   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-August 19

Creating Random Sentence, one by one

Posted 23 August 2019 - 06:48 PM

I am having an issue getting a program to function correctly. I have to generate 10 random sentences, one at a time. I have gotten the application to generate all 10 at once. The code I have written is working perfectly, but I need to be able to click a btnNext and have the sentences generate with each click. Rather than all at once. Currently I have: [ Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
        'Variable declarations
        Dim randomValue As New Random  'Creating a random variable.
        Dim intCount As Integer  'Counter loop or index tracker.
        Dim index As Integer 'Inner indexes

        'Create ten new random sentences.
        For intCount = 0 To 9
            Dim rndSentence As String = " "

            '1) Articles
            index = randomValue.Next(0, strArticles.GetUpperBound(0))
            rndSentence &= strArticles(index) & " "

            '2) Adjectives
            index = randomValue.Next(0, strAdjectives.GetUpperBound(0))
            rndSentence &= strAdjectives(index) & " "

            '3) Nouns
            index = randomValue.Next(0, strNouns.GetUpperBound(0))
            rndSentence &= strNouns(index) & " "

            '4) Verbs
            index = randomValue.Next(0, strVerbs.GetUpperBound(0))
            rndSentence &= strVerbs(index) & " "

            '5) Prepositions
            index = randomValue.Next(0, strPrepositions.GetUpperBound(0))
            rndSentence &= strPrepositions(index) & " "

            '6) Articles
            index = randomValue.Next(0, strArticles.GetUpperBound(0))
            rndSentence &= strArticles(index) & " "

            '7) Adjectives
            index = randomValue.Next(0, strAdjectives.GetUpperBound(0))
            rndSentence &= strAdjectives(index) & " "

            '8) Nouns
            index = randomValue.Next(0, strNouns.GetUpperBound(0))
            rndSentence &= strNouns(index) & "."

            lstRandomSentences.Items.Add(rndSentence)

        Next




    End Sub]
:code:

For the click event handler for btnNEXT.

The last issue I am having is getting the first letter of the first word in the sentence to capatilize. Nothing in my text shows how to do this and everything I am finding online doesn't work and returns errors. Please help me!

This post has been edited by modi123_1: 23 August 2019 - 08:34 PM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: Creating Random Sentence, one by one

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,167
  • Joined: 12-June 08

Re: Creating Random Sentence, one by one

Posted 23 August 2019 - 08:36 PM

If you don't want to have all ten at once then stop doing that. That means remove the for loop. Keep track of the count in a global variable .

I mean I get you yoinked the code from here, but do attempt it on your own first.

https://www.dreaminc...y-using-arrays/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1