Complex Text Strings|Variables

  • Thread starter Thread starter cogent
  • Start date Start date
C

cogent

Hello

I have a VBA program which creates scripts. Large portions of the script
are "static" so I do not want to clutter the code for writing the "variable"
part of the script with the static content (200 lines).

I thought a solution would be to have a string variable which is equal to
the static portion of the script then append it to the variable portion once
it has been created, then save out the final appended file to disk.

The static portion is 200 lines of text, however. How can I create a text
variable in VBA to "equal" the static 200 lines of text?

Many thanks in advance

W
 
Not sure what you mean.
Are you meaning self-modifying code? In which case you'll need to do a
search for VBE in help
There are some examples on my website.
Chip Pearson has some good information too:
http://www.cpearson.com/excel/vbe.htm


If you're meaning some very long string:

str = "this is line 1" & vbNewLine & _
"this is line 2" & vbNewLine
str = str & _
"this is line 3" & vbNewLine & _
"this is line 4" & vbNewLine
 
Store the static 200 lines in a text file and have your program read
the file contents into a variable.
Or paste the 200lines into a cell and read it from there.


Tim.
 
On a side note - does anyone know the max length of a single string
variable? I thought I'd read somewhere that it's 65536 chars, but that
might've been for an earlier version of vba or for vb6.
 
String limits:
Fixed length 2^16 (~ 65000)
Variable Length 2^31 (~ 2 billion)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top