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
Printable View
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
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?
Quote:
Originally Posted by RhinoBull
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.
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
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?Quote:
Originally Posted by RhinoBull
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.
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
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:Quote:
Originally Posted by Besoup
VB Code:
Open App.Path & "\Log\CurrendDayLogFile.log" For Append As #1 Print #1, "some new log" Close #1
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 ...Quote:
Originally Posted by [LGS]Static
Just can't believe it - the right hand doesn't know what left is doing ... :p
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?Quote:
Originally Posted by RhinoBull
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.
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.
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
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.
this is untested but if you do something like this:
then you can display a certain number of lines in the textboxVB Code:
Dim Lines() As String Open "c:\Logfile.txt" For Input As #1 lines = Split(Input(LOF(1),1),vbcrlf) Close #1 For x = UBound(lines) To 0 Step -1 If UBound(lines) - x > 20 Then 'change 20 to the number of lines you want to display Exit For End If text1 = text1 & lines(x) & vbcrlf Next x
the most recent data will be at the top...
Here's an example that removes the first line of text after a hundred are found.
VB Code:
Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long Private Const EM_GETLINECOUNT = &HBA Private Const EM_LINELENGTH = &HC1 Private Const MAX_LINES = 100 ' This could be 1000, 5000, etc. ' This code would be placed at the start of the sub that adds the lines to the textbox Dim lngCount As Long Dim lngLineIndex As Long Dim lngLength As Long Dim strBuffer As String lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0) If lngCount = MAX_LINES Then With Text1 'get line length of the first line lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0) ' select line 2 to the end .SelStart = lngLength .SelLength = Len(.Text) strBuffer = Space(.SelLength) strBuffer = .SelText ' replace all the text with the line 2 to the end text .Text = strBuffer End With 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.Quote:
Originally Posted by MartinLiss
Add the highlighted code and let me know what happens.
VB Code:
lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0) If lngCount = MAX_LINES Then With Text1 'get line length of the first line lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0) ' select line 2 to the end .SelStart = lngLength .SelLength = Len(.Text) strBuffer = Space(.SelLength) strBuffer = .SelText ' replace all the text with the line 2 to the end text [HL="#FFFF80"]If Left$(strBuffer, 2) = vbCrLf Then strBuffer = Right$(strBuffer, Len(strBuffer) - 2) End If[/HL] .Text = strBuffer End With 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.Quote:
Originally Posted by MartinLiss
I guess I need to see your code because the above works for me.
VB Code:
Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long Private Const EM_GETLINECOUNT = &HBA Private Const EM_LINELENGTH = &HC1 Private Const MAX_LINES = 10 ' This could be 1000, 5000, etc. Private Sub addStatus(stStuff As String, stType As String) Dim lngCount As Long Dim lngLineIndex As Long Dim lngLength As Long Dim strBuffer As String If txtStatus.Text <> "" Then txtStatus.Text = stType & stStuff & "...." & vbNewLine & txtStatus.Text Else txtStatus.Text = stType & stStuff & "...." End If lngCount = SendMessage(txtStatus.hwnd, EM_GETLINECOUNT, 0, 0) If lngCount = MAX_LINES Then With txtStatus 'get line length of the first line lngLength = SendMessage(.hwnd, EM_LINELENGTH, 0, 0) ' select line 2 to the end .SelStart = lngLength .SelLength = Len(.Text) strBuffer = Space(.SelLength) strBuffer = .SelText ' replace all the text with the line 2 to the end text If Left$(strBuffer, 2) = vbCrLf Then strBuffer = Right$(strBuffer, Len(strBuffer) - 2) End If .Text = strBuffer End With End If End Sub
Make the following change
VB Code:
'If Text1.Text <> "" Then ' Text1.Text = stType & stStuff & "...." & vbNewLine & Text1.Text 'Else ' Text1.Text = stType & stStuff & "...." 'End If If Text1.Text <> "" Then Text1.Text = Text1.Text & vbNewLine & stType & stStuff & "...." Else Text1.Text = stType & stStuff & "...." End If
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.
Quote:
Originally Posted by MartinLiss
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.
Besoup,
Try this project and see what you think. It will work with any text display box. Textbox or RTFTextBox etc...
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.Quote:
Originally Posted by Besoup
Here it is reversed. Note the addition of the new constant.
VB Code:
Private Const EM_LINEINDEX = &HBB
VB Code:
Private Sub addStatus(stStuff As String, stType As String) Dim lngCount As Long Dim lngLineIndex As Long Dim lngLength As Long Dim strBuffer As String lngCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0) If lngCount = MAX_LINES Then With Text1 'get line length of the last line lngLineIndex = SendMessage(.hwnd, EM_LINEINDEX, MAX_LINES - 1, 0) 'get line length lngLength = SendMessage(.hwnd, EM_LINELENGTH, lngLineIndex, 0) ' select the 1st to next to last lines .SelStart = 0 .SelLength = Len(.Text) - lngLength strBuffer = Space(.SelLength) strBuffer = .SelText ' replace all the text with the 1st to next to last lines If Right$(strBuffer, 2) = vbCrLf Then strBuffer = Left$(strBuffer, Len(strBuffer) - 2) End If .Text = strBuffer End With End If If Text1.Text <> "" Then Text1.Text = stType & stStuff & "...." & vbNewLine & Text1.Text Else Text1.Text = stType & stStuff & "...." End If End Sub
Did that resolve your problem? BTW Bruce Fox pointed out to me that the SendMessageStr API in my original example isn't being used so you can delete it.
couldn't a list view or a listbox sufficed as well? Is there any reason for it to be a text box?
Tg
Thanks everyone, got it with Martin's code. You guys rock!
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.Quote:
Originally Posted by randem