Hello everybody!
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.
Take a look at the image...
Printable View
Hello everybody!
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.
Take a look at the image...
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
thanks really works,
but since 8 boxes that should be 8 characters only
what if i type lower than 8 letters,
I'll try lower than 8 letters the other boxes that already have letters is not been erase...
I want if how many letters i put in text box word that should be appear in boxes only..
Well, then you need to 'clean up' the textboxes before fill them, as :
Code:Dim I As Integer
For I = 0 To 8
Text2(I).Text = ""
Next I
For I = 1 To Len(Text1.Text)
Text2(I-1).Text = Mid(Text1.Text,I,1)
Next I
Simpler:Code:For i = 0 To 7
If i < len(Text1.Text) Then
Text2(i).Text = Mid$(Text1.Text, i + 1 ,1)
Else
Text2(i).Text = ""
End if
Next
Code:For i = 0 To 7
Text2(i).Text = Mid$(Text1.Text, i + 1 ,1)
Next
Thanks man....jggtz
really works again
and another code from anhn
thanks to you also
And one more way to skin a catCode: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
how about i want to split the textbox and then sort it in ascending or desascending order and then display the output in another textbox?
for numbers only on a textbox,
example textbox 1, value is 42315
then
textbox 2 will be 12345, help plss
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
here is another optionCode: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!
sorry for posting here cause i am new here, thanks it worked