-
Feb 24th, 2012, 05:27 PM
#1
Thread Starter
Hyperactive Member
Textbox holding more than 65535 characters using API
Could someone give me a direction on this?
This code from another source (with a minor change by me to print a bunch of "x"'s instead of blank spaces), suggests that you can use the API to get a textbox to hold more than 65535 characters. When I try it, the textbox is just plain white...no characters. At least none that I can see. I have gone to my API reference and everything looks just like it should be. So I am thinking the problem is because I haven't included code to tell what color to use for the text. Is this the case?
Many thanks!
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 Const WM_SETTEXT = &HC
Private Const EM_SETSEL = &HB1
Private loopo As Long
Private Sub Command1_Click()
'Getting textbox to hold more than 65535 characters
'Code by strongm at tek-tips.com, 6/2/2008:
'Controls:
'Command button named "Command1".
'Textbox named "Text1", w vertical scrollbar.
Dim result As Long
Dim maxstring As String
' Simple demo that we can go over 65535 by just one extra character
'maxstring = Space(65535) + "x"
For loopo = 1 To 65536
maxstring = maxstring + "x"
Next loopo
SendMessage Text1.hwnd, WM_SETTEXT, 0&, ByVal maxstring
Debug.Print Len(Text1.Text) ' Note that once we've actually got the text into the textbox we can get it out (or information about it) OK
SendMessage Text1.hwnd, EM_SETSEL, Len(Text1.Text), Len(Text1.Text)
Exit Sub
' Ok, let's be silly, and go with, say, 64Mb + 1...
maxstring = Space(1024& * 1024 * 64) + "x"
SendMessage Text1.hwnd, WM_SETTEXT, 0&, ByVal maxstring
Debug.Print Len(Text1.Text)
' Position selection at end to demonstrate that Textbox can happily hold and
' display rather more text than we might expect ...
' Cannot use Textbox's own SetSel because that is limited by MS to a max of 65535
' (mind you, you'll notice a performance problem
SendMessage Text1.hwnd, EM_SETSEL, Len(Text1.Text), Len(Text1.Text)
End Sub
-
Feb 24th, 2012, 06:45 PM
#2
Re: Textbox holding more than 65535 characters using API
If I'm not mistaken the richtextbox does not have this limitation. I would try that if I needed to have that much data in a text box.
-
Feb 24th, 2012, 10:33 PM
#3
Re: Textbox holding more than 65535 characters using API
Try this:
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 Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim i As Long
Dim strText As String
Screen.MousePointer = vbHourglass
For i = 0 To 10000
strText = strText & CStr(i) & " Now is the time for all good men" & vbCrLf
Next
SendMessage Text1.hwnd, WM_SETTEXT, 0&, ByVal strText
Screen.MousePointer = vbDefault
MsgBox Len(Text1.Text), vbInformation, "Len(Text1.Text)"
End Sub
-
Feb 24th, 2012, 11:49 PM
#4
Thread Starter
Hyperactive Member
Re: Textbox holding more than 65535 characters using API
If I'm not mistaken the richtextbox does not have this limitation. I would try that if I needed to have that much data in a text box.
Funny you should mention that! . I was having problems with an RTB and I was wondering if it had a limit. But it was another problem. But in the meantime, I was researching textbox limits and ran into this bit of code. So I thought I would just play with it and maybe add it to my "vb toolkit" for future use. But it doesn't print like it should.
DrUnicode> I tried your code but same problem. Could this be a vb6 under Win7 problem?
-
Feb 25th, 2012, 09:48 AM
#5
Re: Textbox holding more than 65535 characters using API
Works here with Win7 32-bit. Did you set TextBox to MultiLine before testing?
-
Feb 25th, 2012, 03:43 PM
#6
Thread Starter
Hyperactive Member
Re: Textbox holding more than 65535 characters using API
DoH! Grade school error there. I'm getting old.
It DOES work.
I may have to use this code as it turns out, because I have >65535 characters of text in an RTB I need to convert to plain text, and the easiest way seems to be copying the RTB into a Plain-Textbox, then parsing my strings from there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|