Spin “Spinning Syntax” Text Using VB.Net

A simple text spinner program using VB.Net, used  to spin text written in the familiar spinning syntax e.g. {sample|example|exhibit}

This program doesn’t spin nested syntax.

You’ll need:

2 Text Boxes (TextBox1, TextBox2)

1 Button (Button1)

Code:



Public Class Form1
    Dim str As String
    Dim strAll
    Dim strStart = 1
    Dim strEnd = 1
    Dim words As Array
    Dim word
    Dim intRWord As Integer
    Dim spin = 1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox2.Text = TextBox1.Text

        Do While spin = 1
            If InStr(strEnd, TextBox2.Text, "{", CompareMethod.Text) > 0 Then
                strStart = InStr(strEnd, TextBox2.Text, "{", CompareMethod.Text)
                strEnd = InStr(strStart, TextBox2.Text, "}", CompareMethod.Text)
                strAll = Mid(TextBox2.Text, strStart, strEnd - strStart + 1)
                str = Mid(TextBox2.Text, strStart + 1, strEnd - strStart - 1)
                words = Split(str, "|", -1, CompareMethod.Text)
                intRWord = words.GetUpperBound(0) * Rnd()
                word = words.GetValue(intRWord)

                TextBox2.Text = Replace(TextBox2.Text, strAll, word, 1, 1, CompareMethod.Text)
                strStart = 1
                strEnd = 1
            Else
                spin = 0

            End If
        Loop
        spin = 1
    End Sub
End Class

Text Spinner Using VB.Net