Results 1 to 21 of 21

Thread: Long Line in Unformatted ANSI TextBox

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Long Line in Unformatted ANSI TextBox

    I've got several little "utility" programs where I have a need to display a VERY long single line of text (sometimes > 1 million characters). They're lines out of XML files, and, other than some HTML tags, they're always numbers. So, if I'm restricted to ANSI, that's not a problem.

    I've discussed this before, and I'm currently using the SCIVB2.OCX Scintilla control to get this done. However, I'm not terribly happy with that control. If I could do it with something more akin to a regular VB6 TextBox, that'd be better.

    Also, I don't need a horizontal scrollbar, as all I'd ever be doing with the data is possibly putting it into the clipboard, and I can do that with a button (so long as this TextBox has a way to "select all"). I suppose if I had the option for a horizontal scrollbar, I wouldn't turn it down. Actually, a runtime toggle for the horizontal scrollbar would be very nice.

    Ideally, I'd like the source code to a custom UC that got this done.



    Just as an FYI, I also put a post in Krool's Common Controls to see what it'd take to have his TextBoxW accomplish this (and it currently doesn't).



    For anyone who might like to play around with this, I've attached a zipped TXT file with a VERY long line in it. If you want to get that line in the clipboard, I'd recommend using Notepad++ (as Windows Notepad also chokes on these things).
    Attached Files Attached Files
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  2. #2
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Wink Re: Long Line in Unformatted ANSI TextBox

    Maybe I didn't understand from your description but why would you want to put a single long line of text in a TextBox if you don't want to scroll through or edit it?

    Anyway I've just tested and it works perfectly fine with my RichEdit and MsftEdit lightweight Unicode Textbox.

    Code:
        With richTest2
            .MaxLength = 2000000
            .Text = String$(1000000, vbKeyA) & "Z"
        End With
        Debug.Print Len(richTest2)

  3. #3
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,262

    Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by Elroy View Post
    I don't need a horizontal scrollbar, as all I'd ever be doing with the data is possibly putting it into the clipboard, and I can do that with a button (so long as this TextBox has a way to "select all").
    Of course, who is going to read a million characters in a textbox?

    Cut the data at for example 10,000 characters and store the actual whole data in a variable.

    If the user selected all, you can know that, and then copy to the clipboard the data from the variable. The built-in copy won't work, or you'll have to subclass it.

  4. #4

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by VanGoghGaming View Post
    Maybe I didn't understand from your description but why would you want to put a single long line of text in a TextBox if you don't want to scroll through or edit it?
    You didn't mis-read. There are a few different cases where I use the SCIVB2.ocx control for this:

    • Just showing a line where I'm also reporting the count of numbers in the line, possibly also reporting min-and-max values for the numbers.
    • Auto-generating the lines, where I might manually paste them back into an XML file I'm working with in NP++.
    • Just sometimes showing the line(s) from an XML file where I'm massaging certain things.

    When writing some utility program that auto-edits these lines (such as maybe adding 10 to every 3rd number), it's just nice to see the line that's being editing, just for verification.



    I tried Krool's RichTextBox and it didn't work. However, I didn't try the standard RTB. I'll try it in a moment and see what happens for me.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Re: Long Line in Unformatted ANSI TextBox

    I haven't tried Krool's TextBox but if it's not based on the newer "MsftEdit.dll" like mine then it's not going to work. You could continue using your Scintilla control or you could take a look at my work (feel free to change it to suit your purposes). I was just curious to test this very long line of characters and it worked fine.

  6. #6

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Ok, it's sort of interesting.

    I tried RichTx32.ocx, and it works, sort of. I can paste the line in, but I can't scroll to the end of it no matter what I try. However, if I do a ctrl+A then ctrl+C, and then go to Notepad++, and paste, it pastes the complete line. So, apparently the RTB can accept the line. It just can't show it to us.

    Regarding Krool's RichTextBox, it truncates the line at 65536 (&h10000) characters. Apparently Krool has set some buffer at that length.



    VanGogh, I'll test yours now.



    Just as a further FYI, even though I won't be scrolling through the line, it would be nice to be able to tap my "End" key and see the end of it (for validation purposes).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    @VanGogh:

    I just tried yours (both the richTest1 and richTest2 in your demo), and they're both truncating the long line at 32768 (&h8000) characters.



    I also tried your MSFTEDIT50W constant and got the same results. And your OFFICERICHEDIT60W constant didn't work at all.
    Last edited by Elroy; Sep 14th, 2024 at 03:44 PM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  8. #8
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Question Re: Long Line in Unformatted ANSI TextBox

    Have you tried the code snippet I posted above (post #2)? I just slapped that in "Form_Click" from the same demo... It definitely writes 1 million "A" characters and one "Z" at the end in the single line RichTextBox at the top!

  9. #9
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Talking Re: Long Line in Unformatted ANSI TextBox

    For some reason it appears you need to set the text programatically (not pasting from the Clipboard with Ctrl-V):

    Code:
        With richTest2
            .Text = Clipboard.GetText
        End With
        Debug.Print Len(richTest2)
    That works with your long line of numbers. At least then you can scroll through it and edit at will.

  10. #10
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Red face Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by Elroy View Post
    I also tried your MSFTEDIT50W constant and got the same results. And your OFFICERICHEDIT60W constant didn't work at all.
    MSFTEDIT50W is the default one and for OFFICERICHEDIT60W you need to have Microsoft Office installed (and copy its "riched20.dll" file in your App.Path folder) because that DLL is not shipped with Windows but it's supposed to be more feature-rich!

  11. #11

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Ok, that's working. I see you've got a MaxLength property.

    Interestingly, it worked, but when I tapped the "End" key, it was doing some funky things with ForeColor and BackColor. Not sure what that was about. The screenshot is with MY test line pasted into it.

    Name:  FunkyColors.png
Views: 70
Size:  4.8 KB

    But this might be workable. I see that you're using CreateWindowEx to create the rich text window.

    I'll play around with this some more though, possibly seeing if it can be worked into a custom UC.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Wink Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by Elroy View Post
    Interestingly, it worked, but when I tapped the "End" key, it was doing some funky things with ForeColor and BackColor. Not sure what that was about.
    Hahaha, well it's a demo isn't it? It's supposed to showcase some features, in this case when you select a piece of text it will randomly change the background and foreground colors!

    But this might be workable. I see that you're using CreateWindowEx to create the rich text window.

    I'll play around with this some more though, possibly seeing if it can be worked into a custom UC.
    Yeah, "CreateWindowEx" is the backbone of all such controls created from scratch out of Microsoft DLLs. Initially I slapped it directly on the form and it worked fine except it had no control whatsoever over when it got or lost focus and also Tab navigation wouldn't work. Then I learned I should've implemented the "IOleInPlaceActiveObject" interface and was like, that's more than I've bargained for! So I ended up creating a PictureBox container for it at runtime and everything was magically fixed.

    Feel free to put it in a full-fledged UC but I'm not sure it's worth the trouble since the runtime PictureBox does exactly the same thing...

  13. #13

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Hmm, I got the bright idea of trying to send a EM_SETLIMITTEXT message to a regular VB6 TextBox, but that didn't work at all. Here's the code I used:

    Code:
    
    Option Explicit
    Private Declare Function SendMessageVal Lib "user32" Alias "SendMessageW" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Any, ByVal lParam As Any) As Long
    
    Private Sub Form_Activate()
        Const EM_SETLIMITTEXT As Long = &HC5&
        SendMessageVal Text1.hWnd, EM_SETLIMITTEXT, 3000000, 0&
    End Sub
    
    
    When I pasted a long line into the Text1 TextBox, it just hung. I guess the windows "Edit" control just can't do it.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  14. #14
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Red face Re: Long Line in Unformatted ANSI TextBox

    The older "RICHEDIT20W" also can't do it (at least it doesn't crash), that's why I suggested the newer MSFTEDIT50W or the Office one (if you got it).

  15. #15
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    809

    Re: Long Line in Unformatted ANSI TextBox

    If IOleInPlaceActiveObject is not used with the API created control, Validate event won't fire for the previous control that just lost focus when the user clicks on the API created one, and also Tab and navigation keys. I don't know if putting it on a PictureBox would solve this, never tried it.

  16. #16
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Re: Long Line in Unformatted ANSI TextBox

    Good to know! I think of the runtime PictureBox as the poor man's IOleInPlaceActiveObject implementation!

    I haven't tested Validate events for previous controls but the Tab navigation works beautifully and that's what annoyed me the most. Also the PictureBox comes in handy for a host of other properties that it can lend to the RichTextBox (such as BackColor, Enabled, Font, ForeColor, TabIndex, Tag, Visible).

  17. #17

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Turning it all into a custom UC will probably accomplish the same thing, as that's about the same as just putting it onto a PictureBox.

    I've got other things going on, but I'll eventually get to this. Probably won't be a full-blown RTF control though, as that's not what I need.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  18. #18
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,490

    Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by Elroy View Post

    Regarding Krool's RichTextBox, it truncates the line at 65536 (&h10000) characters. Apparently Krool has set some buffer at that length.
    Elroy,
    65536 is the default limit for every rich edit if the .MaxLength property ( EM_EXLIMITTEXT for rich edit) is set to 0.
    And 0 is the default for the VBCCR RichTextBox.
    So, to change it set .MaxLength to 1M or more..

    And to others: the VBCCR RichTextBox is using msftedit.dll and fallbacks to riched20.dll if msftedit.dll does not exist.
    Last edited by Krool; Sep 15th, 2024 at 05:20 AM.

  19. #19
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,829

    Re: Long Line in Unformatted ANSI TextBox

    the hex-editors around they can read huge files. but that doesn't mean its all in memory.
    the same can be done here. u only show "-page height to +page height" or something, so when u move down/up (or left/right) it will be updated accordingly.
    its not much difference from my visual novel game where I have 12 million letters (total or 2 million words), I dont show everything at once.
    think of "page" each page can show "X" amount. and u go from there.

  20. #20

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,521

    Re: Long Line in Unformatted ANSI TextBox

    Quote Originally Posted by Krool View Post
    Elroy,
    65536 is the default limit for every rich edit if the .MaxLength property ( EM_EXLIMITTEXT for rich edit) is set to 0.
    And 0 is the default for the VBCCR RichTextBox.
    So, to change it set .MaxLength to 1M or more..

    And to others: the VBCCR RichTextBox is using msftedit.dll and fallbacks to riched20.dll if msftedit.dll does not exist.
    Krool,

    This is good to know. I might use yours and do more testing with the EM_EXLIMITTEXT property. It seems like this might be an excellent solution, and I definitely like the idea of it already being a custom UC.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  21. #21
    Frenzied Member VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,004

    Thumbs up Re: Long Line in Unformatted ANSI TextBox

    It looks like "EM_EXLIMITTEXT" is better than "EM_SETLIMITTEXT" since it also increases Paste limits (not only the limit of text entered programmatically).

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