This is an auxiliary code that takes a text from the clipboard and generates code for a constant declaration, then copies it back to the clipboard converted.
It could be useful for someone.
Last edited by Eduardo-; May 14th, 2021 at 11:43 AM.
Re: (VB6) Turn multiline text into String constant
This is the way with the least code
【String line breaks "_" are spliced, and cannot exceed 25 lines, otherwise an error occurs, and the prompt "Too many line continuation flags"】
Code:
Function StrToVbCode_(ByVal Str As String, VarName As String, Optional ByConst As Boolean) As String
Str = Replace(Str, Chr(34), Chr(34) & Chr(34))
While Right(Str, 2) = vbCrLf
Str = Left(Str, Len(Str) - 2)
Wend
StrToVbCode_ = IIf(ByConst, "Private Const " & VarName & " As String = ", " Dim " & VarName & " As String : " & VarName & " = ") _
& Chr(34) & Chr(34) & " _" & vbCrLf & " & " & Chr(34) _
& Replace(Str, vbCrLf, Chr(34) & " & vbCrLf _" & vbCrLf & " & " & Chr(34)) _
& Chr(34)
End Function
Last edited by xiaoyao; May 14th, 2021 at 05:06 AM.
Re: (VB6) Turn multiline text into String constant
In the past I've used multi-line text concatenation, mostly for web post submissions. For example, data collection, crawlers automatically release information. You may need to post five to ten different addresses from login to operation. The data of each post is different. Key, value, equivalent to JSON data. a=1&b=k&c=33 Some data are fixed, and some are constantly changing. I couldn't think of a better way, so I went with an array of strings.
dim postArr()
redim postArr(1)
postArr(0)="a=" & "1"
postArr(1)="b=" & bvalue
Re: (VB6) Turn multiline text into String constant
Originally Posted by xiaoyao
I Don't understand. Where did you update?
In the project attached to the first post.
Originally Posted by xiaoyao
The main problem is your code, I feel very strange, I can't understand it.
It is not commented.
It is intended as a tool to be used if needed, but just that. It is in the Codebank because exes are not allowed.
I usually comment the code the second time, when I try to figure what I've done the fist time and need to understand it.
But the first time I'm just focused on making it to work. And when it is done, I usually don't feel like it to spend more time re-studying the code and making comments.
The logic is this:
Convert all non-printable characters to VB code (vbTab, vbCrLf, etc.)
Split into lines that do not occupy more than 1024 characters each.
Split into several constants because one can only have a limited number of line continuations.