Visual Basic Loop and display one line at a time

I am using visual studio 2008, VB9, and I am trying to write an application that mainly performs calculations on a set of data entered by the user. During the calculations, I want to display data at each step and save them in the display area in the graphical interface (it is not overwritten by the following displayed data).

For example:

UserInput = 1

Do

  UserInput += 1

  OutputLabel.Text = "UserInput " & UserInput

Loop Until UserInput = 5

and the result will look like

UserInput 1 UserInput 2 UserInput 3 UserInput 4 UserInput 5

I tried this and other loop structures and it seems that I didn’t understand everything. The actual application is a little more complicated, but the example is well suited for logical purposes.

Any tips are welcome, thanks!

+5
source share
6

:

Dim delimiter as String = ""
For UserInput As Integer = 1 To 5
    OutputLabel.Text &= String.Format("{0}UserInput {1}", delimiter, UserInput)
    delimiter = " "
Next

, , ( , ):

  • , - , , .

, :

Dim sb As New StringBuilder()
Dim delimiter As String = ""
For UserInput As Integer = 1 To 5
    sb.AppendFormat("{0}UserInput {1}", delimiter, UserInput)
    delimiter = " "
Next
OutputLabel.Text = sb.ToString()

, - ( !):

OutputLabel.Text = Enumerable.Range(1, 5).Aggregate(Of String)("", Function(s, i) s & String.Format("UserInput {0} ", i))
+3

OutputLabel.Text.

OutputLabel.Text &= "UserInput " & UserInput

reset : OutputLabel.Text = ""

+3

, -

For I As Integer = 1 To 5
     If I > 1 Then OutputLabel.Text &= " "
     OutputLabel.Text &= "UserInput " & I.ToString()
End For

, ForEach.

+1

? , , , ,

Console.WriteLine("my string")
+1

, richtextbox

    Dim UserInput As Integer = 0
    Const userDone As Integer = 5

    RichTextBox1.Clear()
    Do

        RichTextBox1.AppendText(String.Format("User input {0:n0}   ", UserInput))
        RichTextBox1.AppendText(Environment.NewLine)
        RichTextBox1.Refresh() 'the data at each step
        UserInput += 1

    Loop Until UserInput = userDone
+1

, , , :

Do
  Dim OutputString as String
  Application.DoEvents() 'to make things paint actively
  UserInput += 1
  OutputString = String.Format("{0}", UserInput)
  ListBox.Items.Add(OutputString)


Loop Until UserInput = 5

, , , . !

+1

All Articles