How to Create a Text Manipulation Tool in Visual Basic

Submitted by: 
Language: 
Visitors have accessed this post 1752 times.

Introduction:
Welcome to my tutorial on how to create a Text Manipulation tool in Visual Basic.

Steps of Creation:
Step 1:

First we want to create a form with one button as 'go', textbox1 to contain the text to manipulate, textbox2 to contain the text reversed, textbox3 to contain the text muddled and textbox4 to contain the total characters of the text.

Step 2:
Now we want to set up our go button. This simply sets the text in the textboxes to the returned string.

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. TextBox2.Text = rev(TextBox1.Text)
  3. doMuddle()
  4. TextBox4.Text = TextBox1.Text.Count() & " Characters."
  5. End Sub

Step 3:
For the reverse function we want to simply run through the characters backwards and return the temporary string.

  1. Private Function rev(ByVal s As String)
  2. Dim ret As String = Nothing
  3. Dim i As Integer = s.Count() - 1
  4. While i > -1
  5. ret &= s.Chars(i)
  6. i -= 1
  7. End While
  8. Return ret
  9. End Function

Step 4:
Finally, for the muddle function we just simply select numbers at random and remove our duplicates.

  1. Private Function doMuddle()
  2. Dim muddle As String = Nothing
  3. Dim doneChars As New List(Of Integer)
  4. Do Until doneChars.Count() - 1 = TextBox1.Text.Count() - 1
  5. Dim rand As Random = New Random()
  6. Dim r As Integer = rand.Next(TextBox1.Text.Count())
  7. Dim isNew As Boolean = True
  8. For Each n As Integer In doneChars
  9. If (n = r) Then isNew = False
  10. Next
  11. If (isNew) Then
  12. muddle &= TextBox1.Text.Chars(r)
  13. doneChars.Add(r)
  14. End If
  15. Loop
  16. TextBox3.Text = muddle
  17. End Function

Project Complete!
Below is the full source code and download to the project files.

  1. Public Class Form1
  2.  
  3. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  4. TextBox2.Text = rev(TextBox1.Text)
  5. doMuddle()
  6. TextBox4.Text = TextBox1.Text.Count() & " Characters."
  7. End Sub
  8.  
  9. Private Function rev(ByVal s As String)
  10. Dim ret As String = Nothing
  11. Dim i As Integer = s.Count() - 1
  12. While i > -1
  13. ret &= s.Chars(i)
  14. i -= 1
  15. End While
  16. Return ret
  17. End Function
  18.  
  19. Private Function doMuddle()
  20. Dim muddle As String = Nothing
  21. Dim doneChars As New List(Of Integer)
  22. Do Until doneChars.Count() - 1 = TextBox1.Text.Count() - 1
  23. Dim rand As Random = New Random()
  24. Dim r As Integer = rand.Next(TextBox1.Text.Count())
  25. Dim isNew As Boolean = True
  26. For Each n As Integer In doneChars
  27. If (n = r) Then isNew = False
  28. Next
  29. If (isNew) Then
  30. muddle &= TextBox1.Text.Chars(r)
  31. doneChars.Add(r)
  32. End If
  33. Loop
  34. TextBox3.Text = muddle
  35. End Function
  36. End Class

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.