I just want to ask what code shall I use if a textbox with MaxLength of 8 characters which you input be split per letter / each letter of the word you input will be placed to another textbox.
You can use For-Next and textbox array, as :
Text1 will contain the typed word
Text Boxes that will contain each letter is an Array of Textboxes
from Text2(0) to Text2(7)
Code:
Dim I As Integer
For I = 1 To Len(Text1.Text)
Text2(I-1).Text = Mid(Text1.Text,I,1)
Next I
Option Explicit
Private Sub Command1_Click()
Dim strWord As String
Dim i As Integer
strWord = StrConv(txtWord.Text, vbUnicode)
For i = 0 To 7
txtLetters(i).Text = ""
Next i
For i = 0 To UBound(Split(strWord, Chr(0))) - 1
txtLetters(i).Text = Split(strWord, Chr(0))(i)
Next i
End Sub
Private Sub Form_Load()
'Restrict word length
txtWord.MaxLength = 8
End Sub
Welcome to the forums jhaybe! Please do not post new questions in other user's thread. You should create a new thread concerning your new Question. But here is how you could do it.
Code:
Private Sub SortNumbers(Textbox_To_Sort As Textbox, Textbox_After_Sort As Textbox)
Dim i As Integer
Dim TempNumber As Integer
Dim ArrNumber() As Integer
Dim KeepSorting As Boolean
If Not IsNumeric(Textbox_To_Sort) Then
MsgBox "Sorry I can only sort Numbers! Please make sure the Textbox contains Numbers only!"
Exit Sub
End If
ReDim ArrNumber(Len(Textbox_To_Sort.Text))
For i = 1 To Len(Textbox_To_Sort.Text)
ArrNumber(i) = Mid(Textbox_To_Sort.Text, i, 1)
Next
Do
KeepSorting = False
For i = 1 To UBound(ArrNumber) - 1
If ArrNumber(i) > ArrNumber(i + 1) Then
TempNumber = ArrNumber(i + 1)
ArrNumber(i + 1) = ArrNumber(i)
ArrNumber(i) = TempNumber
KeepSorting = True
End If
Next
DoEvents 'Not needed! But I like to put a DoEvents in a loop just in case the loop goes infinite.(Program will not freeze)
Loop Until KeepSorting = False
Textbox_After_Sort.Text = vbNullString
For i = 1 To UBound(ArrNumber)
Textbox_After_Sort.Text = Textbox_After_Sort.Text & ArrNumber(i)
Next
End Sub
Private Sub Command1_Click()
SortNumbers Text1, Text2
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim intStartLen As Integer
Dim intEndLen As Integer
Dim strIn As String
Dim strOut As String
Dim strTemp As String
strIn = Text1.Text
For i = 0 To 9
intStartLen = Len(strIn)
strIn = Replace(strIn, CStr(i), "")
intEndLen = Len(strIn)
strTemp = String(intStartLen - intEndLen, CStr(i))
strOut = strOut & strTemp
Next i
Text2.Text = strOut
End Sub
a slight modification to my code and you could sort bigger numbers then 0 to 9. Of course you would need to seperate them with a delimiter and then user Split()... Instead of pooulation the array with each char of the textbox you use use a string NumberArray and use Split() and populate the array like that.
But for only 1 to 9 you could go simple and use the excellent idea of MarkT!