For Loops to prompt a user for 5 facts about a topic.

Matthew Turcotte 1 Reputation point
2021-03-19T17:04:26.157+00:00

Any suggestions on how to start a for loop to prompt the user for five facts about a topic. I am a beginner and have not done well with for loops wit past sections and am trying to grasps the concept. I am supposed to create the facts had the user use a input box to get a fact set to a string variable add the fact to the list box. I have a menu box that I have added add fact, remove fact, clear list, and close. I am pretty lost on how to start this code if anyone has any educational tips that they could share with me I would appreciate it.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2021-03-20T16:28:44.357+00:00

    Here is the base logic where entering nothing or pressing cancel will exit the loop.

    Public Class Form1
        Private Sub EnterFactsButton_Click(sender As Object, e As EventArgs) Handles EnterFactsButton.Click
    
            FactsListBox.Items.Clear()
    
            Dim factIndex = 1
    
            While True
    
                Dim value = InputBox($"Enter fact {factIndex}")
    
                If String.IsNullOrWhiteSpace(value) OrElse factIndex = 5 Then
                    Exit While
                Else
                    FactsListBox.Items.Add(value)
                    factIndex += 1
                End If
    
            End While
    
        End Sub
    End Class
    
    1 person found this answer helpful.
    0 comments No comments