fox
Junior Member
Posts: 66
|
Post by fox on Apr 13, 2024 9:42:00 GMT -5
Hi all. I would like to know what is the easiest way to limit the maximun of characters that a texteditor (created with LB 4.5.1 command) can accept before it stops to receive data. Thanks to all and bye. fox
|
|
|
Post by tsh73 on Apr 13, 2024 10:49:44 GMT -5
found here, a post in un-related thread (https://libertybasiccom.proboards.com/thread/1552/error-handling) by alincon
So it said it works for textboxes. Have no idea about text editor...
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 13, 2024 11:28:03 GMT -5
Thanks a lot, tsh73. I will try. Bye fox
|
|
|
Post by xxgeek on Apr 13, 2024 11:58:28 GMT -5
After testing with the code below I found the texteditor can !selectall then !cut, or !copy ALL the text as long as the length of the text is less than 70040 bytes(characters)
Any file over that length will not attempt a "!selectall" or "!copy", but reports to a statictext instead when length exceeds the maximum clipboard capability.
What you need is the max length of the text can not exceed: 70040 Check the text in the texteditor before attempting a !selectall with !copy or !cut . May affect other text commands, didn't test any further myself.
nomainwin WindowWidth = 800:WindowHeight = 600 texteditor #test.txted, 20, 30, 750, 500 button #test.bttn, "Get a File to Test", [newFile], ul, 5, 10, 130, 20 button #test.bttnCopy, "Copy Text", [copyText], ul, 265, 10, 70, 20 textbox #test.fileLength, 140, 10, 120, 20 statictext #test.st "",340,15,250,15 open "CODEBANK v1.0" for window as #test #test "trapclose [quit.main]" wait
[newFile] #test.st "" filedialog "Open \ Select a Just Basic Source File (.bas) ", "c:\"; "\*.*", Filename$ open Filename$ for input as #1 fileText$=input$(#1,lof(#1)) close #1 #test.txted "!contents fileText$"; #test.fileLength len(fileText$);" Bites" if len(fileText$)<70040 then #test.txted "!selectall" #test.txted "!copy" #test.st "TextEditor Contents Copied to Clipboard" else #test.st "TextEditor Contents Too Big to Copy to Clipboard" end if wait
[copyText] #test.txted "!contents? fileText2$"; if len(fileText2$)<70040 then #test.txted "!selectall" #test.txted "!copy" #test.txted "!contents? fileText2$"; #test.fileLength len(fileText2$);" Bytes" #test.st "TextEditor Contents Copied to Clipboard" else #test.st "TextEditor Contents Too Big to Copy to Clipboard" #test.fileLength len(fileText2$);" Bytes" end if wait
[quit.main] close #test end
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 13, 2024 12:26:20 GMT -5
Thanks a lot, xxgeek. I will try the code. Bye fox
|
|
|
Post by xxgeek on Apr 13, 2024 12:38:12 GMT -5
The code still needs work. It isn't accurate fox. I'm using len(Filename$). It doesn't report correctly what we need. May need to use something else, like counting the # lines, or line input to count each character (slow for big files). Off to the drawing board again
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 13, 2024 12:46:05 GMT -5
Ok. Thanks and bye. fox
|
|
|
Post by Rod on Apr 13, 2024 13:13:20 GMT -5
Are we talking about someone typing 70k characters from the keyboard or perhaps measuring the lof() before the error occurs. How do we get to the position of trying to pack 70k characters into an edit/display control thst is far more suited to typed user input? Perhaps the process needs reassessed?
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 13, 2024 15:24:48 GMT -5
Hi Rod. Please, excuse me for my bad English: I try to explain my idea. I would like to be able to limit characters in a texteditor. So, if my limit is (for example) 200 characters, when I try to store the two hundred and first character texteditor stops to work. How (I think) it is possible to limit characters in a text box. Thanks and bye. fox
|
|
|
Post by xxgeek on Apr 13, 2024 15:52:42 GMT -5
Sounds more like a textbox than a texteditor. Different animal. To limit entries to 200 characters You just need to check the textbox length every time before adding any more input to it. Might need a loop depending on what you are doing. As usual, posting your code helps a lot, and can sometimes bridge the language barrier too.
|
|
|
Post by Rod on Apr 14, 2024 1:50:25 GMT -5
The texteditor was custom built by Carl and so cannot respond to normal API tricks. The solution as xxgeek states is to regularly check the contents and within thst check limit the length of text to 200.
A multi line textbox might be a solution and as it is a standard windows control it will respond to API tricks. pretty sure there will be something in the LBPE. I will check later.
And yes, code will get much better advice.
|
|
emy
New Member
Hello
Posts: 45
|
Post by emy on Apr 14, 2024 3:27:08 GMT -5
'The following code works for a Textbox nomainwin WindowWidth = 360 : WindowHeight = 190 UpperLeftX = 100 : UpperLeftY = 10 textbox #w.tb1, 80, 30, 200, 25 Button #w.bt1, "&Exit", [quitw], UL, 150, 90, 60, 40 '......................... open "Number of characters limitation for textbox" for dialog_modal as #w #w "trapclose [quitw]" '......................... Limit = 8 '8 = number of characters limite, value can be changed call SetTextLimit hwnd(#w.tb1), Limit '(Limit = number of characters) wait '---------------- [quitw] close #w End '---------------- sub SetTextLimit TextBoxHwnd, Limit CallDll #user32, "SendMessageA",_ TextBoxHwnd as ulong,_ _EM_SETLIMITTEXT as long,_ Limit as long,_ 0 as long,_ SetTextLimit as long end sub '----------------
|
|
|
Post by Rod on Apr 14, 2024 3:50:39 GMT -5
emy is on the right track but a textbox is not a texteditor. You can manipulate a textbox with API but it has limitations. This is a combination of demos from the LBPE and Alyce that turn a textbox into a multiline control that limits input to 100 characters. However it is quirky. (for example you need to press Ctrl+Enter to get a new line.) The advice is to move to a full function multiline texteditor and Alyce offers one, or use the regular measuring trick that xxgeek suggests on a texteditor control. You will need to experiment. Alyces texteditor www.alycesrestaurant.com/Utilities.htm Nomainwin WindowWidth=200 WindowHeight=300
text1$ = "STYLEBITS allows you to change the style of a Liberty BASIC window or control." text2$ = "Add to or edit this text."
Textbox #Main.txtbx, 0, 0, 190, 190 Stylebits #Main.txtbx, _WS_VSCROLL OR _ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0 Statictext #Main, text2$, 5, 200, 190, 30 Open "LineWrap for LB" for Window_nf as #Main
'get the textbox handle and limit the character length to 100 hText = hWnd(#Main.txtbx) flag = _EM_LIMITTEXT Call SendMessageLong hText,flag,100,0
#Main "Trapclose EndDemo" #Main.txtbx text1$ Wait
Sub EndDemo handle$ Close #Main End End Sub
Sub SendMessageLong hWnd,msg,wParam,lParam CallDLL #user32, "SendMessageA",_ hWnd As uLong, _ msg As Long,_ wParam As Long,_ lParam As Long,_ re As Long End Sub
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 14, 2024 4:54:38 GMT -5
Hi Rod. It is very interesting the code you propose. I will try an study carefully it. Thanks a lot and bye. fox
|
|
|
Post by xxgeek on Apr 14, 2024 6:59:45 GMT -5
Thanks for posting emy. I knew I'd seen that code before somewhere but couldn't find it. Nice simple function to limit the text in a textbox, and adjustable too. Scooped for future use Rod once posted in the JB forum a nice loop checking the textbox prior to adding text, with a hidden textbox(or was it a graphicbox), also used _vk codes, but I can't find that either. We could guess all week what fox needs, but a piece of code from fox would at least show if we're working with a textbox, or a an editor. Personally I would like to finish the code I posted above for a texteditor. It would be nice to know prior to doing a !copy or !cut from a texteditor whether or not the LB limit for the clipboard is going to be exceeded, and avoid it with a workaround. The math gets in my way. My worst subject in math was always converting a word problem into an equation. There is a relationship between the number of empty lines, and the length of the text in an editor. I'd bet tsh73(Anatoly) could figure it out in a few seconds.
|
|