Results 1 to 33 of 33

Thread: [RESOLVED] Character limit in text box?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [RESOLVED] Character limit in text box?

    Is there a limit to the amout of text that you can enter into a text box? If so does anyone know what it is? Thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    It's set to 32K for a for multiple-line regular textbox and 64K for RichTextBox (I think) which is a very large number ... What are you trying to load into the textbox?
    Last edited by RhinoBull; Aug 3rd, 2005 at 08:39 AM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by RhinoBull
    It's set to 64K which is a very large number ... What are you trying to load into the textbox?

    I am just making an app that is writing status of actions the app is performing. Kind of like a running log that the user could scroll through.... the thing is this app will be running 24/7 and doing something different every 20-30 seconds.

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Character limit in text box?

    a richtextbox can handle more I think

    And if your program is going to be running 24/7, it would be a good idea to backup everything into a .log file every few hours

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    You don't write logs to a textbox but textfile or database and let user load file for a specific day or records from database (or something like that).

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by RhinoBull
    You don't write logs to a textbox but textfile or database and let user load file for a specific day or records from database (or something like that).
    is there a way to directly link a text file into an app and keep adding to it?

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    Apparently (per Microsoft) RichTextBox's max is limited by the available memory so in any case it lets you display alot more text in it.

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Character limit in text box?

    lol.. looking up limits:

    Textbox is 32K limit..
    The I found this about RichText
    "However, the RichTextBox control doesn't have the same 64K character capacity limit of the conventional TextBox control."

    doesnt have the same limit of 64K like a textbox?? but..its...um.. 32K? lol..nice
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    Quote Originally Posted by Besoup
    is there a way to directly link a text file into an app and keep adding to it?
    I don't how you do it in the first place but you can simply use Open ... For Append logic to add to existing file but also you may want to create new file every day:
    VB Code:
    1. Open App.Path & "\Log\CurrendDayLogFile.log" For Append As #1
    2.     Print #1, "some new log"
    3. Close #1

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    Quote Originally Posted by [LGS]Static
    lol.. looking up limits:

    Textbox is 32K limit..
    The I found this about RichText
    "However, the RichTextBox control doesn't have the same 64K character capacity limit of the conventional TextBox control."

    doesnt have the same limit of 64K like a textbox?? but..its...um.. 32K? lol..nice
    That's what I thought it was - the 64K but then I saw in the MSDN the darn 32K so I modified my first reply ...
    Just can't believe it - the right hand doesn't know what left is doing ...

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by RhinoBull
    I don't how you do it in the first place but you can simply use Open ... For Append logic to add to existing file but also you may want to create new file every day:
    VB Code:
    1. Open App.Path & "\Log\CurrendDayLogFile.log" For Append As #1
    2.     Print #1, "some new log"
    3. Close #1
    yeah writing to a file is no problem... is there a way I could maybe insert an instance of the word.exe inside my app and keep writing to it maybe? so it is visible to the user?

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Character limit in text box?

    An instance of MS Word? No, that's too much for creating and displaying logs, though. Use RichTextBox but that's not how you create log - you write to a file in the background - when user wants to see it he/she will manually open it.

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    You could write every line to a file as it comes in and at the same time you could use SendMessage you could count the number of lines that were displayed and when the number of lines reached 1000 (5000?, 10,000?) you could begin the delete the old lines from the display as the new ones come in and in that way always have a "Last 1000" display.

  14. #14
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Character limit in text box?

    Agreed

    log files are usually for Debug / checking if errors.. if the user needs to see it they can either open it.. oy maybe in a menu you can have an option to view the log file, in which case you could shell notepad to open it
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Yeah I could probably just limit the actual display of the text box. Is there a way I could count how many line breaks are in the box and remove any old entries after say 100 line breaks?

    I will be writing to a log file also but I would like to display the most recent data going into it.

  16. #16
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Character limit in text box?

    this is untested but if you do something like this:
    VB Code:
    1. Dim Lines() As String
    2. Open "c:\Logfile.txt" For Input As #1
    3.     lines = Split(Input(LOF(1),1),vbcrlf)
    4. Close #1
    5.  
    6. For x = UBound(lines) To 0 Step -1
    7.     If UBound(lines) - x > 20 Then 'change 20 to the number of lines you want to display
    8.         Exit For
    9.     End If
    10.     text1 = text1 & lines(x) & vbcrlf
    11. Next x
    then you can display a certain number of lines in the textbox
    the most recent data will be at the top...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  17. #17
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    Here's an example that removes the first line of text after a hundred are found.

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    3.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    4. Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _
    5.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    6. Private Const EM_GETLINECOUNT = &HBA
    7. Private Const EM_LINELENGTH = &HC1
    8. Private Const MAX_LINES = 100 ' This could be 1000, 5000, etc.
    9.  
    10. ' This code would be placed at the start of the sub that adds the lines to the textbox
    11.     Dim lngCount As Long
    12.     Dim lngLineIndex As Long
    13.     Dim lngLength As Long
    14.     Dim strBuffer As String
    15.    
    16.     lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    17.     If lngCount = MAX_LINES Then
    18.         With Text1
    19.             'get line length of the first line
    20.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0)
    21.             ' select line 2 to the end
    22.             .SelStart = lngLength
    23.             .SelLength = Len(.Text)
    24.             strBuffer = Space(.SelLength)
    25.             strBuffer = .SelText
    26.             ' replace all the text with the line 2 to the end text
    27.             .Text = strBuffer
    28.         End With
    29.     End If

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by MartinLiss
    Here's an example that removes the first line of text after a hundred are found.

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    3.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    4. Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _
    5.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    6. Private Const EM_GETLINECOUNT = &HBA
    7. Private Const EM_LINELENGTH = &HC1
    8. Private Const MAX_LINES = 100 ' This could be 1000, 5000, etc.
    9.  
    10. ' This code would be placed at the start of the sub that adds the lines to the textbox
    11.     Dim lngCount As Long
    12.     Dim lngLineIndex As Long
    13.     Dim lngLength As Long
    14.     Dim strBuffer As String
    15.    
    16.     lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    17.     If lngCount = MAX_LINES Then
    18.         With Text1
    19.             'get line length of the first line
    20.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0)
    21.             ' select line 2 to the end
    22.             .SelStart = lngLength
    23.             .SelLength = Len(.Text)
    24.             strBuffer = Space(.SelLength)
    25.             strBuffer = .SelText
    26.             ' replace all the text with the line 2 to the end text
    27.             .Text = strBuffer
    28.         End With
    29.     End If
    Tried this and switched the line max lines to 10, was fine for the first 9 entries then the tenth entry would be blank. It would then allow me to keep adding more entries without remove any, just every tenth entry was a blank line.

  19. #19
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    Add the highlighted code and let me know what happens.

    VB Code:
    1. lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    2.     If lngCount = MAX_LINES Then
    3.         With Text1
    4.             'get line length of the first line
    5.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0)
    6.             ' select line 2 to the end
    7.             .SelStart = lngLength
    8.             .SelLength = Len(.Text)
    9.             strBuffer = Space(.SelLength)
    10.             strBuffer = .SelText
    11.             ' replace all the text with the line 2 to the end text
    12.             [HL="#FFFF80"]If Left$(strBuffer, 2) = vbCrLf Then
    13.                 strBuffer = Right$(strBuffer, Len(strBuffer) - 2)
    14.             End If[/HL]
    15.             .Text = strBuffer
    16.         End With
    17.     End If

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by MartinLiss
    Add the highlighted code and let me know what happens.

    VB Code:
    1. lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    2.     If lngCount = MAX_LINES Then
    3.         With Text1
    4.             'get line length of the first line
    5.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0)
    6.             ' select line 2 to the end
    7.             .SelStart = lngLength
    8.             .SelLength = Len(.Text)
    9.             strBuffer = Space(.SelLength)
    10.             strBuffer = .SelText
    11.             ' replace all the text with the line 2 to the end text
    12.             [HL="#FFFF80"]If Left$(strBuffer, 2) = vbCrLf Then
    13.                 strBuffer = Right$(strBuffer, Len(strBuffer) - 2)
    14.             End If[/HL]
    15.             .Text = strBuffer
    16.         End With
    17.     End If
    Now it gives me the first 9 entries and that is all... It won't let me add anymore and it isn't removing any.

  21. #21

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    3.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    4. Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _
    5.         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    6. Private Const EM_GETLINECOUNT = &HBA
    7. Private Const EM_LINELENGTH = &HC1
    8. Private Const MAX_LINES = 10 ' This could be 1000, 5000, etc.
    9.  
    10.  
    11. Private Sub addStatus(stStuff As String, stType As String)
    12. Dim lngCount As Long
    13. Dim lngLineIndex As Long
    14. Dim lngLength As Long
    15. Dim strBuffer As String
    16.  
    17. If txtStatus.Text <> "" Then
    18.     txtStatus.Text = stType & stStuff & "...." & vbNewLine & txtStatus.Text
    19. Else
    20.     txtStatus.Text = stType & stStuff & "...."
    21. End If
    22.         lngCount = SendMessage(txtStatus.hwnd, EM_GETLINECOUNT, 0, 0)
    23.     If lngCount = MAX_LINES Then
    24.         With txtStatus
    25.             'get line length of the first line
    26.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0)
    27.             ' select line 2 to the end
    28.             .SelStart = lngLength
    29.             .SelLength = Len(.Text)
    30.             strBuffer = Space(.SelLength)
    31.             strBuffer = .SelText
    32.             ' replace all the text with the line 2 to the end text
    33.             If Left$(strBuffer, 2) = vbCrLf Then
    34.                 strBuffer = Right$(strBuffer, Len(strBuffer) - 2)
    35.             End If
    36.             .Text = strBuffer
    37.         End With
    38.     End If
    39. End Sub

  23. #23
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    Make the following change

    VB Code:
    1. 'If Text1.Text <> "" Then
    2. '    Text1.Text = stType & stStuff & "...." & vbNewLine & Text1.Text
    3. 'Else
    4. '    Text1.Text = stType & stStuff & "...."
    5. 'End If
    6. If Text1.Text <> "" Then
    7.     Text1.Text = Text1.Text & vbNewLine & stType & stStuff & "...."
    8. Else
    9.     Text1.Text = stType & stStuff & "...."
    10. End If

  24. #24
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Character limit in text box?

    Besoup,

    What I would do to limit the text shown on screen would be Write all data to log file and put data line into a circular array (queue). in this way you always know the start and end of your data to copy to the textbox.

    If you had an array of 100 entries, you would start at 1 and put a line in each entry until you get to the 100th entry then start at 1 again. You will always have the last 100 lines written to the log file and can output them to the textbox anytime you like.

  25. #25

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Quote Originally Posted by MartinLiss
    Make the following change

    VB Code:
    1. 'If Text1.Text <> "" Then
    2. '    Text1.Text = stType & stStuff & "...." & vbNewLine & Text1.Text
    3. 'Else
    4. '    Text1.Text = stType & stStuff & "...."
    5. 'End If
    6. If Text1.Text <> "" Then
    7.     Text1.Text = Text1.Text & vbNewLine & stType & stStuff & "...."
    8. Else
    9.     Text1.Text = stType & stStuff & "...."
    10. End If

    This works kinda... It is just going backwards. The newest entry is going to the bottom of the list and the ones being erased are on the top.

  26. #26
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Character limit in text box?

    Besoup,

    Try this project and see what you think. It will work with any text display box. Textbox or RTFTextBox etc...
    Attached Files Attached Files

  27. #27
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    Quote Originally Posted by Besoup
    This works kinda... It is just going backwards. The newest entry is going to the bottom of the list and the ones being erased are on the top.
    That's what I think most people would expect in that it would look like it's scrolling off the screen. However you should be able to take the code and reverse it. If you need help doing that please let me know.

  28. #28
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Character limit in text box?

    Here it is reversed. Note the addition of the new constant.

    VB Code:
    1. Private Const EM_LINEINDEX = &HBB

    VB Code:
    1. Private Sub addStatus(stStuff As String, stType As String)
    2. Dim lngCount As Long
    3. Dim lngLineIndex As Long
    4. Dim lngLength As Long
    5. Dim strBuffer As String
    6.  
    7.  
    8.     lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    9.     If lngCount = MAX_LINES Then
    10.         With Text1
    11.             'get line length of the last line
    12.             lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, MAX_LINES - 1, 0)
    13.             'get line length
    14.             lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0)
    15.             ' select the 1st to next to last lines
    16.             .SelStart = 0
    17.             .SelLength = Len(.Text) - lngLength
    18.             strBuffer = Space(.SelLength)
    19.             strBuffer = .SelText
    20.             ' replace all the text with the 1st to next to last lines
    21.             If Right$(strBuffer, 2) = vbCrLf Then
    22.                 strBuffer = Left$(strBuffer, Len(strBuffer) - 2)
    23.             End If
    24.             .Text = strBuffer
    25.         End With
    26.     End If
    27.    
    28.     If Text1.Text <> "" Then
    29.         Text1.Text = stType & stStuff & "...." & vbNewLine & Text1.Text
    30.     Else
    31.         Text1.Text = stType & stStuff & "...."
    32.     End If
    33.  
    34. End Sub

  29. #29

  30. #30
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Character limit in text box?

    couldn't a list view or a listbox sufficed as well? Is there any reason for it to be a text box?

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  31. #31

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Character limit in text box?

    Thanks everyone, got it with Martin's code. You guys rock!

  32. #32
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Character limit in text box?

    Besoup,

    So, you did not like my code, huh?

  33. #33

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [RESOLVED] Character limit in text box?

    Quote Originally Posted by randem
    Besoup,

    So, you did not like my code, huh?
    Dude I loved your code and will be using it in the future. Just went with what I was already working with. Thanks tho.

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