Results 1 to 12 of 12

Thread: Splitting each Letters of words in textBox

  1. #1

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Splitting each Letters of words in textBox

    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...
    Attached Images Attached Images  

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Splitting each Letters of words in 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
    Last edited by jggtz; Dec 9th, 2009 at 10:48 AM.

  3. #3

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: Splitting each Letters of words in textBox

    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..
    Last edited by morkie; Dec 9th, 2009 at 07:18 PM.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Splitting each Letters of words in textBox

    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

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Splitting each Letters of words in textBox

    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
    Simpler:
    Code:
        For i = 0 To 7
            Text2(i).Text = Mid$(Text1.Text, i + 1 ,1)
        Next
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6

    Thread Starter
    Addicted Member morkie's Avatar
    Join Date
    Jan 2009
    Location
    P4
    Posts
    202

    Re: Splitting each Letters of words in textBox

    Thanks man....jggtz
    really works again
    and another code from anhn
    thanks to you also

  7. #7
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Splitting each Letters of words in textBox

    And one more way to skin a cat
    Code:
    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
    Last edited by MarkT; Dec 10th, 2009 at 09:49 AM.

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Re: Splitting each Letters of words in textBox

    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

  9. #9
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Splitting each Letters of words in textBox

    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

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Splitting each Letters of words in textBox

    here is another option
    Code:
    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

  11. #11
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Splitting each Letters of words in textBox

    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!

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Re: Splitting each Letters of words in textBox

    sorry for posting here cause i am new here, thanks it worked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width