Question Add looping text into text box.

alternator

New member
Joined
Feb 19, 2010
Messages
3
Programming Experience
3-5
Hello,

I'm new to VB.Net. I try to convert from VB6 to VB.Net (2008) with a simple code as shown in the picture below but its come up with Warning. Did anyone know how to solve this warning. Sorry for lame question..

err1dq.jpg
 
Either ignore it (because using a var as TARGET is okay if it has no value), or declare your var like this:
Dim a As String = String.Empty
 
Since you're new to VB.Net, this is how I would rewrite the code:
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  Handles MyBase.Load
    Dim sb As New System.Text.StringBuilder()
    For i As Integer = 1 To 10
        sb.AppendLine("abcdefg")
    Next
    Text1.Text = sb.ToString
End Sub

You typically want to use a stringbuilder when manipulating strings for performance & memory concerns. When concatenating strings without the StringBuilder, new memory is used each time. In contrast, a StringBuilder will reuse the memory when adding more text. With such a small amount of text as is the case here, the benefit won't be noticed. But it's always good to use best practices.

There's no need to update the Textbox's text inside the loop.
 
Back
Top