How many characters can a string hold?
I need to read a very long string and pass it to an external exe. I am currently using a string to store the data, but when it is over 255, the string gets messed up...
Any ideas?
thanks
Printable View
How many characters can a string hold?
I need to read a very long string and pass it to an external exe. I am currently using a string to store the data, but when it is over 255, the string gets messed up...
Any ideas?
thanks
From VB Help:
There are two kinds of strings: variable-length and fixed-length strings.
A variable-length string can contain up to approximately 2 billion (2^31) characters.
A fixed-length string can contain 1 to approximately 64K (2^16) characters.
Note APublic fixed-length string can't be used in aclass module.
Roy
How long is your long data ?
String can hold ...
(variable-length) 10 bytes + string length
0 to approximately 2 billion.
I cannot imagine your need is bigger than this.
http://www.vbforums.com/
Can you see a problem with my code?
Dim stringbufferOld As String
Call readCurrentRegEnv
strNewEnvVarShort = Command$()
If strNewEnvVarShort = "" Then
MsgBox "Path to append is null. Please enter a valid path", vbCritical, "ERROR!"
Unload Me
Exit Sub
End If
' remove "\" from the end of the new string
Do While Right(strNewEnvVarShort, 1) = "\"
strNewEnvVarShort = Left(strNewEnvVarShort, Len(strNewEnvVarShort) - 1)
Loop
stringbufferOld = stringbuffer
stringbuffer = stringbuffer & ";" & strNewEnvVarShort
myArray = Split(stringbuffer, ";")
numbPaths = UBound(myArray) + 1
For i = 0 To numbPaths - 1
If Not myArray(i) = "" Then
If Not i = numbPaths - 1 Then
strNewEnvVar = strNewEnvVar & myArray(i) & ";"
Else
strNewEnvVar = strNewEnvVar & myArray(i)
End If
End If
Next i
'check if the new path statement already exists in current path
If InStr(stringbufferOld, strNewEnvVarShort) > 0 Then
'MsgBox "exists"
Else
'MsgBox "doesn't exist"
strPath = """" & strNewEnvVar & """" & " -m" 'system variables
Shell (App.Path & "\setx.exe " & "PATH " & strPath)
MsgBox (App.Path & "\setx.exe " & "PATH " & strPath)
End If
'default path: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
Unload Me
Exit Sub
End Sub
Call readCurrentRegEnv === returns existing environment path
I haven't thoroughly checked the logical processing of your code, but I may first suspect the Command() function may only return 255 characters...
try checking the length of strNewEnvVarShort after this :
VB Code:
strNewEnvVarShort = Command$()
to see if it does not mess it up....
Also, I don't see enough information in the cost you posted about this:
VB Code:
stringbuffer = stringbuffer & ";" & strNewEnvVarShort
stringbuffer is neither declared nor initialized before the above command. Therefore, I cannot tell how it was declared or initialized.
It could also be that passing the string back to the Shell command that limits it to 255 characters.
could you post the code for readCurrentRegEnv? It might be the source of the problem.