Entering Large Amounts of Text

Entering Large Amounts of Text

I have a problem with writing text in Visual Basic. I would like to enter several hundred pages of text into my program, Any ideas of how to do this easily? The Label Box and Text box allow very little and will not work to my knowledge. And I don’t want to have type Print “” every time I write a line. If you have any ideas I would appreciate it if you would reply!

You might want to look at one of the VBXs that allows larger amounts of text than just 64k (or 32k in the case of VB3.0). You may also want to look at changing your program so that it automatically saves the text whenever you get a certain amount of text into the box. Once the limit is reached, the program saves the text, clears the box, and you continue typing.The problem here is that it will soon become a real bear trying to keep track of the saved text. One suggestion would be to save them in separate, serially numbered files (e.g. myproj01.txt, myproj02.txt, etc.) and keep track of each of them in an array so that you can “page” forward and back between the files. To ease the transition time between “pages” you can read in an entire textfile “in a gulp” like this:

Dim FileHnd As Long       ‘this sets up a variable for the file handle (for the Open statement)Dim FileBuffer As String   ‘this will be used as a buffer to receive the contents of the text fileFileHnd = FreeFile           ‘assign a file handle number to our variable’this next line puts together a string of spaces into the FileBuffer variable’note that I hardcoded the “C:setuplog.txt” for my test because it was about 60k and’already on my harddrive.  Use any filename you want (including a passed variable with the’pathfilename in it)FileBuffer = String(FileLen(“C:setuplog.txt”), ” “)Open “C:setuplog.txt” For Binary As FileHnd   ‘open the file for binaryGet #FileHnd, , FileBuffer                                  ‘read the whole thing into the bufferText1.Text = FileBuffer                                      ‘assign the buffer’s contents to your textboxClose #FileHnd                                                  ‘clean up after yourself
There is also the option of going to a custom control. There are several large text listboxes listed in the File Archives page of Ask the VB Pro.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist