Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA string 255 character limitation

Tags:

string

vba

I'm facing issues working with VBA and noting that it has a string limitation to 255 characters. I'm actually trying to send a JSON through POST and pausing the execution I note that the string has always just 255 characters.

Is there a way to resize the string or something?

like image 236
Gonzo345 Avatar asked Sep 06 '25 20:09

Gonzo345


2 Answers

I wasted around 6 hours into this problem to finally check that it was just a DEBUGGER LIMITATION . The VBA debugger just shows 255 characters of the string, but it doesn't mean that it contains just what he's showing.

I noticed about this when things were getting crazy and it went to the surface when I used a MsgBox with a Len to check the string size and content.

Hope it helps, because I read lots of people asking for this but nobody told about it.

like image 151
Gonzo345 Avatar answered Sep 10 '25 01:09

Gonzo345


If you want to print something on the console (immediate window) you may simply Print it to a notepad, the result would be theoretically the same and above the 255 lines (not characters). Here is how to print the numbers from 1 to 10.000 in a notepad:

Option Explicit

Public Sub PrintToNotepad()

    Dim strShell                As String
    Dim strFileName             As String
    Dim fs                      As Object
    Dim objText                 As Object

    strFileName = ThisWorkbook.Path & "\test" & Replace(Now, ":", "")
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set objText = fs.CreateTextFile(strFileName, True)

    objText.writeline (GenerateBigString)

    strShell = "C:\WINDOWS\notepad.exe" & " "
    strShell = strShell & strFileName
    Call Shell(strShell)

End Sub

Public Function GenerateBigString() As String

    Dim i           As Long
    Dim result      As String

    For i = 1 To 10000
        result = result & i & vbCrLf
    Next i

    GenerateBigString = result

End Function
like image 37
Vityata Avatar answered Sep 10 '25 01:09

Vityata