CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    17

    split long text ? help please

    hi all

    i write this code and it work fine to split the text to equal part

    put the problem is that ....

    for example i need to see a msgbox with only max characters of "45" there no problem if it is less than 45 to see full last word

    example text

    The decision to bail out carmaker Chrysler was made by the narrowest of margins, President Obama's former "car czar" reveals.

    now with this app i will see msg box with

    The first msgbox = The decision to bail out carmaker Chrysler wa
    The second one is = s made by the narrowest of margins, President
    The third one is =Obama's former "car czar" reveals.


    i need to see this ::

    The first msgbox = The decision to bail out carmaker Chrysler
    The second one is = was made by the narrowest of margins,
    The third one is = President Obama's former "car czar" reveals.

    i need to add a code to check the last character if it is "space" or not if not i need it to reduce value of aa until he found a "space" and show the split text.





    Code:
    Dim a As Integer
    Dim b As Integer
    Dim c As Integer 
    Dim lf As Integer
    Dim aa As Integer
    Dim bb As Integer
    Dim newa As String
    
    aa = 45
    bb = 1
    
    
    a = Len(Text1.Text) / aa
    b = a + 1
    c = 0
    
    
    
    
    For lf = 1 To b
    
    newa = Mid$(Text1.Text, bb, aa)
    bb = bb + aa
    MsgBox newa
    Next lf
    
    
    End Sub
    regards

  2. #2
    Join Date
    Oct 2010
    Posts
    17

    Re: split long text ? help please

    there no one know a soulation ???
    regards

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: split long text ? help please

    See if this helps:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim a$, x%
        a = "This   is   a         test."
        x = InStr(a, "  ")
        If x > 0 Then
          Do While InStr(a, "  ")
            a = Replace(a, "  ", " ")
          Loop
        End If
        MsgBox a
    End Sub
    This is a test.
    EDIT: Or, use a RichTextBox, and turn WORDWRAP on!
    Last edited by dglienna; October 29th, 2010 at 01:10 AM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: split long text ? help please

    First check to see if text length > 45.
    If >45 then is character 45 a space
    If yes then split the string here and add a crlf
    If not a space then use a loop to step backwards through the 45 characters until you find a space and split the string at that point.
    Repeat the process with the remaining portion of the string until the last part is 45 or less.
    Always use [code][/code] tags when posting code.

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

Featured