Half triangle + half diamond:
Dim a, b, row As Integer
row = 6
For a = 1 To row
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (a & " ")
Next
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
For a = 5 To 1 Step -1
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (a & " ")
Next
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
Half triangle + half diamond reversed:
Dim a, b, c, row As Integer
row = 6
For a = 1 To row
For c = a To row
Me.TextBox1.Text = Me.TextBox1.Text & (" ")
Next c
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (a)
Next b
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
For a = 5 To 1 Step -1
For c = a To row
Me.TextBox1.Text = Me.TextBox1.Text & (" ")
Next c
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (a)
Next b
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
to make a full diamond or a pyramid add * 2 -1
Capitalize specific index in a string:
Dim x As String = Me.TextBox1.Text
Dim result As String = ""
While i < x.Length For i As Integer = 0 To x.Length - 1
If i Mod 2 = 0 Then
' Even
result &= Char.ToLower(x(i))
Else
' Odd
result &= Char.ToUpper(x(i))
End If
I += 1
Next
End while
Me.TextBox2.Text = result
To start on the first letter simply change the Even
into “Char.ToUpper”
And Odd into “Char.toLower”
Fibonacci Sequence:
Dim a, b, c, d, j As Integer
c = Val(TextBox1.Text)
a = 0
b = 1
Me.TextBox2.Text = a & " " & b
For d = 1 To c - 2
j = a + b
Me.TextBox2.Text = Me.TextBox2.Text & " " & j
a = b
b = j
Next
Composite or Prime Number:
Dim a, b, c As Integer
Dim d As String = ""
c = Val(TextBox1.Text)
b = 0
For a = 2 To c - 1
If c Mod a = 0 Then
b = 1
End If
Next
If b = 0 Then
d = "Number is prime"
Else
d = "Number is composite"
End If
TextBox2.Text = d
Normal number sequence pyramid/diamond:
Dim a, b, c, row As Integer
row = 9
For a = 1 To row - 4
For c = 1 To 5 - a
Me.TextBox1.Text = Me.TextBox1.Text & (" ")
Next c
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (a)
Next b
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
For a = 6 To row
For c = 1 To a - 5
Me.TextBox1.Text = Me.TextBox1.Text & " "
Next c
For b = 1 To 10 - a
Me.TextBox1.Text = Me.TextBox1.Text & (a)
Next b
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
Capitalize every first letters:
Dim result As String = TextBox1.Text
Dim textinfo As TextInfo = New CultureInfo("en-US", False).TextInfo
result = TextInfo.ToTitleCase(result)
Me.TextBox2.Text = result
Arrow shaped by 2/static intervals:
Dim a, b, row As Integer
row = 7
For a = 1 To row Step 2
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (" ")
Next
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & ("*")
Next
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
For a = 5 To 1 Step -2
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & (" ")
Next
For b = 1 To a
Me.TextBox1.Text = Me.TextBox1.Text & ("*")
Next
Me.TextBox1.Text = Me.TextBox1.Text & Environment.NewLine
Next
To reverse add “step 2 and -2”
Do, While , For loops comparison:
Dim a, b As Integer Dim a, b As Integer Dim a, b As Integer
a = 1 a = 1
Do While (a <= 5) For a = 1 To 5
b = 1 b = 1 For b = 1 To a
Do While (b <= a) Me.TextBox1.Text =
Me.TextBox1.Text = Me.TextBox1.Text = Me.TextBox1.Text & "*"
Me.TextBox1.Text & "*" Me.TextBox1.Text & "*"
b = b + 1 b = b + 1 Next
End While Me.TextBox1.Text =
Me.TextBox1.Text = Me.TextBox1.Text & vbNewLine
Loop While (b <= a) Me.TextBox1.Text & vbNewLine Next
Me.TextBox1.Text = a = a + 1
Me.TextBox1.Text & vbNewLine End While
a = a + 1
Loop While (a <= 5)
Arrow shaped but with dynamic intervals/increments:
Dim pattern As String = ""
Dim row As Integer = 1 ' Initial number of asterisks
Dim increment As Integer = 3 ' Initial increment value
' Generate the upper half of the pattern
Do While row <= 8
' Add spaces before the asterisks
Dim i As Integer = 1
Do While i <= row
pattern &= " "
i += 1
Loop
' Append the current row of asterisks to the pattern
Dim j As Integer = 1
Do While j <= row
pattern &= "*"
j += 1
Loop
pattern &= Environment.NewLine
' Adjust the row and increment values
If row = 4 Then ' When row reaches 4, change the increment to 2
increment = 2
End If
row += increment
Loop
' Reset row and increment for the lower half
row = 6 ' Initial number of asterisks for lower half
increment = -2 ' Initial decrement value for lower half
' Generate the lower half of the pattern
Do While row >= 1
' Add spaces before the asterisks
Dim i As Integer = 1
Do While i <= row
pattern &= " "
i += 1
Loop
' Append the current row of asterisks to the pattern
Dim j As Integer = 1
Do While j <= row
pattern &= "*"
j += 1
Loop
pattern &= Environment.NewLine
' Adjust the row and decrement values
If row = 4 Then ' When row reaches 4, change the decrement to -3
increment = -3
End If
row += increment
Loop
' Display the pattern in TextBox1
TextBox1.Text = pattern
To reverse, simply change blank space from do loop to for next
Pyramid number:
Dim pattern As String = ""
Dim row As Integer = 1
Dim increment As Integer = 1
Dim m As Integer = 1
Dim x As Integer = 1
Do While row <= 5
Dim i As Integer = 1
Do While i <= 5 - row
pattern &= " "
i += 1
Loop
Dim j As Integer = 1
Do While j <= (2 * row) - 1
pattern &= (m)
m += x
j += 1
Loop
pattern &= Environment.NewLine
If row = 3 Then
m = 9
x = 0
End If
If row = 4 Then
m = 9
x = 1
End If
row += increment
Loop
TextBox1.Text = pattern
Reverse while keeping words order:
Dim x As String = Me.TextBox1.Text
Dim result As String = ""
Dim words() As String = x.Split
For Each word As String In words
Dim reversedWord As String = ""
For i As Integer = word.Length - 1 To 0 Step -1
If i Mod 2 = 0 Then
' Even
reversedWord &= Char.ToLower(word(i))
Else
' Odd
reversedWord &= Char.ToUpper(word(i))
End If
Next
result &= reversedWord & " "
Next
Me.TextBox2.Text = result
Reverse except first word:
Dim x As String = Me.TextBox1.Text
Dim result As String = ""
Dim words() As String = x.Split()
For Each word As String In words
Dim reversedWord As String = ""
If words.Length > 0 AndAlso word = words(0) Then
For j As Integer = 0 To word.Length - 1
If j Mod 2 = 0 Then
' Even
reversedWord &= Char.ToLower(word(j))
Else
' Odd
reversedWord &= Char.ToUpper(word(j))
End If
Next
Else
For i As Integer = word.Length - 1 To 0 Step -1
If i Mod 2 = 0 Then
' Even
reversedWord &= Char.ToLower(word(i))
Else
' Odd
reversedWord &= Char.ToUpper(word(i))
End If
Next
End If
result &= reversedWord & " "
Next
Me.TextBox2.Text = result.Trim()