Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Line limit.

  1. #1

    Thread Starter
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Resolved [RESOLVED] [2005] Line limit.

    well i'm trying to make a textbox multiline with a limit of 39 chars per line.
    the divison is made with the conditions of:

    -if the line have a space it divides with the first space.
    -if the line dont have spaces it put a "-" and it pass to the next line.

    the problem is that i'm not reaching the result i whant :S

    my code:
    vb.net Code:
    1. Public Function Check_text()
    2.         Dim myLines As New List(Of String)
    3.         Dim letra As String
    4.         For Each ln As String In Me.TextBox1.Lines
    5.             If ln.Length > 39 Then
    6.                 Dim revtext As String = ReverseString(ln.Substring(0, 38).ToString)
    7.                 Dim pos As Integer
    8.                 pos = InStr(1, revtext, " ")
    9.                 If pos > 0 Then
    10.                     ' We found it.
    11.                     TargetPosition = pos
    12.                     Dim before = revtext.Substring(0, pos + 1).ToString
    13.                     Dim antes = revtext.Substring(pos, ln.Length - pos - 2).ToString
    14.                     Mid(revtext, pos, 1) = ""
    15.                     myLines.Add(ReverseString(antes))
    16.                     myLines.Add(ReverseString(before))
    17.                 Else
    18.                     letra = ln.Substring(38, 1).ToString
    19.                     myLines.Add(ln.Substring(0, 38) & "-")
    20.                     myLines.Add(letra & ln.Substring(39))
    21.                 End If
    22.             Else
    23.                 myLines.Add(ln)
    24.             End If
    25.         Next
    26.         Me.TextBox1.Clear()
    27.         Me.TextBox1.Lines = myLines.ToArray
    28.         Me.TextBox1.SelectionStart = Me.TextBox1.Text.Length
    29.         Check_text = True
    30.     End Function

    ty if you could help


    The Future Is Always The Way To Live The Life

  2. #2

    Thread Starter
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: [2005] Line limit.

    bump someone knows how to helP?? :S i real need this :S


    The Future Is Always The Way To Live The Life

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Line limit.

    You need to be clearer gooden about what the problem actually is... When you say "I'm not reaching the result I want" - it's not very helpful. What does that mean?? Give an example and I'll try and help.


    Also, what's the ReverseString bit? Is that a function or something. I don't know if I've seen it in .NET. And why do you reverse it and then re-reverse it to add it? I'm a little confused.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Line limit.

    Are we on a Service Level Agreement here that I wasn't aware of? All posts must be answered within 24 minutes?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: [2005] Line limit.

    sorry for that jmcilhinney but im a little nervose :S and sorrry for what i did :S

    im going to explain. i use the reverse because the space that it have to be divided on the text is the last space. so i reverse i get the first space and do the operaction. the problem is that variavel "before" and the "antes" is giving me worng :S

    the before is what comes Antes <- "Space" -> before


    ps: i know that is not before and it is after :S if you test the code you will see the error :S


    The Future Is Always The Way To Live The Life

  6. #6
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Line limit.

    There's a much easier way of doing that then without having to reverse the string.

    vb Code:
    1. Dim pos As Integer = ln.LastIndexOf(" "c)

    which will give you the last index of a space. Then you check for the value of pos, so it would be something along the lines of (roughly):

    vb Code:
    1. If pos <> -1 Then   'Space found:
    2.     Dim firstPart As String = ln.Substring(0, pos)   'Get from 1st char up until space
    3.      Dim secondPart As String = ln.Substring(pos + 1)  'Get text that appears after space
    4.      myLines.Add(firstPart)       'Add to Lines
    5.      myLines.Add(secondPart)

    edit - Ooops, yes, changed it to pos as it should have been
    Last edited by stimbo; Jul 20th, 2007 at 10:19 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  7. #7
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] Line limit.

    This isn't the best nor cleaniest. Give it a try and see if it does what you want.

    vb Code:
    1. Public Function Check_text()
    2.         Dim lines() As String = TextBox1.Lines
    3.         Dim checkLines As String
    4.         Dim LeftOverLine As String
    5.         Dim x As Integer
    6.         TextBox1.Clear()
    7.         For x = 0 To lines.Length - 1
    8.             If lines(x).Length > 39 Then
    9.                 checkLines = lines(x).ToString.Substring(0, 38)
    10.                 If InStrRev(checkLines, " ") Then
    11.                     checkLines = Mid(checkLines, 1, InStrRev(checkLines, " "))
    12.                     LeftOverLine = lines(x).ToString.Substring(checkLines.Length, lines(x).ToString.Length - checkLines.Length)
    13.                     TextBox1.AppendText(checkLines & vbNewLine & LeftOverLine & vbNewLine)
    14.                 Else
    15.                     LeftOverLine = lines(x).ToString.Substring(checkLines.Length, lines(x).ToString.Length - checkLines.Length)
    16.                     TextBox1.AppendText(checkLines & "-" & vbNewLine & LeftOverLine & vbNewLine)
    17.                 End If
    18.             End If
    19.         Next
    20.         Return True
    21.     End Function

  8. #8

    Thread Starter
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: [2005] Line limit.

    Quote Originally Posted by stimbo
    There's a much easier way of doing that then without having to reverse the string.

    vb Code:
    1. Dim pos As Integer = ln.LastIndexOf(" "c)

    which will give you the last index of a space. Then you check for the value of pos, so it would be something along the lines of (roughly):

    vb Code:
    1. If pos <> -1 Then   'Space found:
    2.     Dim firstPart As String = ln.Substring(0, findSpace)   'Get from 1st char up until space
    3.      Dim secondPart As String = ln.Substring(findSpace + 1)  'Get text that appears after space
    4.      myLines.Add(firstPart)       'Add to Lines
    5.      myLines.Add(secondPart)


    that findspace is the pos???


    edited:
    I put the pos and worked Ty very much and sorry for what i did :S


    The Future Is Always The Way To Live The Life

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