Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Entering Large Amounts of Text

Question:
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!

Answer:
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 file

FileHnd = 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
'path\filename in it)

FileBuffer = String(FileLen("C:\setuplog.txt"), " ")

Open "C:\setuplog.txt" For Binary As FileHnd   'open the file for binary
Get #FileHnd, , FileBuffer                                  'read the whole thing into the buffer
Text1.Text = FileBuffer                                      'assign the buffer's contents to your textbox
Close #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.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date