JayBeeOH

Textbox Append Test

May 23rd, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.15 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2017. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Textbox Append Test
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   23 MAY 2017
  16. '
  17. ' Description:    Test demonstrates the efficiency of methods and operations to append
  18. '                 text to a textbox.
  19. '
  20. '                 This code is located at: https://pastebin.com/dHkX5iEG
  21. '                 Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  22. '-------------------------------------------------------------------------------------------
  23.  
  24. Imports System.Text
  25.  
  26. Public Class MainForm
  27.  
  28.     Private myString As String = "The quick brown fox jumps over the lazy dog." & Environment.NewLine
  29.     Private sb As New StringBuilder
  30.     Private myStopWatch As New Stopwatch
  31.  
  32.     Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
  33.  
  34.         Dim ampersandEquals As String = AmpersandEqualsFunction()
  35.         Dim appendTo As String = AppendToFunction()
  36.         Dim sbuilder As String = StringBuilderFunction()
  37.  
  38.         MessageBox.Show("Using '&=' to append: " & ampersandEquals & Environment.NewLine &
  39.                         "Using 'AppendText' to append: " & appendTo & Environment.NewLine &
  40.                         "Using 'StringBuilder' to append: " & sbuilder & Environment.NewLine, "Timings")
  41.     End Sub
  42.  
  43.     Private Function AmpersandEqualsFunction() As String
  44.  
  45.         myStopWatch.Reset()
  46.         TextBox1.Clear()
  47.         myStopWatch.Start()
  48.         Do Until TextBox1.TextLength >= (TextBox1.MaxLength - myString.Length)
  49.             TextBox1.Text &= myString
  50.         Loop
  51.         myStopWatch.Stop()
  52.         Return myStopWatch.Elapsed.ToString
  53.     End Function
  54.  
  55.     Private Function AppendToFunction() As String
  56.  
  57.         myStopWatch.Reset()
  58.         TextBox1.Clear()
  59.         myStopWatch.Start()
  60.         Do Until TextBox1.TextLength >= (TextBox1.MaxLength - myString.Length)
  61.             TextBox1.AppendText(myString)
  62.  
  63.         Loop
  64.         myStopWatch.Stop()
  65.         Return myStopWatch.Elapsed.ToString
  66.     End Function
  67.  
  68.     Private Function StringBuilderFunction() As String
  69.  
  70.         myStopWatch.Reset()
  71.         TextBox1.Clear()
  72.         sb.Clear()
  73.         myStopWatch.Start()
  74.         Do Until sb.Length >= (TextBox1.MaxLength - myString.Length)
  75.             sb.Append(myString)
  76.         Loop
  77.         TextBox1.Text = sb.ToString
  78.         myStopWatch.Stop()
  79.         Return myStopWatch.Elapsed.ToString
  80.     End Function
  81.  
  82. End Class
Advertisement
Add Comment
Please, Sign In to add comment