Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2017. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Textbox Append Test
- '
- ' Author: Joseph L. Bolen
- ' Date Created: 23 MAY 2017
- '
- ' Description: Test demonstrates the efficiency of methods and operations to append
- ' text to a textbox.
- '
- ' This code is located at: https://pastebin.com/dHkX5iEG
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '-------------------------------------------------------------------------------------------
- Imports System.Text
- Public Class MainForm
- Private myString As String = "The quick brown fox jumps over the lazy dog." & Environment.NewLine
- Private sb As New StringBuilder
- Private myStopWatch As New Stopwatch
- Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
- Dim ampersandEquals As String = AmpersandEqualsFunction()
- Dim appendTo As String = AppendToFunction()
- Dim sbuilder As String = StringBuilderFunction()
- MessageBox.Show("Using '&=' to append: " & ampersandEquals & Environment.NewLine &
- "Using 'AppendText' to append: " & appendTo & Environment.NewLine &
- "Using 'StringBuilder' to append: " & sbuilder & Environment.NewLine, "Timings")
- End Sub
- Private Function AmpersandEqualsFunction() As String
- myStopWatch.Reset()
- TextBox1.Clear()
- myStopWatch.Start()
- Do Until TextBox1.TextLength >= (TextBox1.MaxLength - myString.Length)
- TextBox1.Text &= myString
- Loop
- myStopWatch.Stop()
- Return myStopWatch.Elapsed.ToString
- End Function
- Private Function AppendToFunction() As String
- myStopWatch.Reset()
- TextBox1.Clear()
- myStopWatch.Start()
- Do Until TextBox1.TextLength >= (TextBox1.MaxLength - myString.Length)
- TextBox1.AppendText(myString)
- Loop
- myStopWatch.Stop()
- Return myStopWatch.Elapsed.ToString
- End Function
- Private Function StringBuilderFunction() As String
- myStopWatch.Reset()
- TextBox1.Clear()
- sb.Clear()
- myStopWatch.Start()
- Do Until sb.Length >= (TextBox1.MaxLength - myString.Length)
- sb.Append(myString)
- Loop
- TextBox1.Text = sb.ToString
- myStopWatch.Stop()
- Return myStopWatch.Elapsed.ToString
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment