0

I encountered something rather curious today while preparing to write a pure vba simple javascript engine. Pulling the document from http, I'd expect to get what it outputs in MsgBox. The plaintext code of the website with javascript tags, etc. I can work with that. Only, I can't work with it if it's only outputting the way I need to the msgbox or a wscript object popup. But if you try to print it to a file, to a cell, etc... the result is what you see in debug.print.

The response in messagebox is the full javascript code and html of the website the way it would show up in a browser if you view page source. The response in debug.print is a different html saying "We're glad you want to do more with your quickbase. Trying to scrape a quickbase page without using the quickbase api.

I'm very curious what is going on here. Different variable type? VarType doesn't indicate that. It can't be something happening on the server's end. Not in my mind anyway. Read through the documentation and I just can't figure it out. What's going on?

grab = CreateObject(WinHttp.WinHttpRequest.5.1")
grab.Open
.SetRequestHeaders "irrelevant", "Really doesn't matter what I'm setting as my headers"
grab.send
' Here's the weird part...
resptext = grab.responseText
respbody = grab.responseBody
debug.print(resptext)
MsgBox(resptext)
string_of_byte_array = StrConv(respbody, vbUnicode)
debug.print(string_of_byte_array)
MsgBox(string_of_byte_array)

Appreciate any clarification you can offer.

  • It's not clear what difference you're seeing, or how we could replicate the problem? – Tim Williams Feb 25 '23 at 23:40
  • The response in messagebox is the full javascript code and html of the website the way it would show up in a browser if you view page source. The response in debug.print is a different html saying "We're glad you want to do more with your quickbase. Trying to scrape a quickbase page without using the quickbase api. – Pete Marise Feb 25 '23 at 23:45
  • which messagebox ? Only the ResponseText one? Can you provide a URL for testing? – Tim Williams Feb 25 '23 at 23:46
  • FYI debug.print can only handle 200 lines, so you will only see the *last* 200 lines when you send a long piece of text to the Immediate pane. – Tim Williams Feb 25 '23 at 23:48
  • Response body as well. I split response into an array and printed each element. Same thing. Gimme a minute to get a similar link. – Pete Marise Feb 25 '23 at 23:55
  • Actually, the 200 line max might answer it if that's representative of the maximum string size it can accept. And if that limit applies to printing to a cell in excel too. I'm going to test it tomorrow with that in mind. Post as an answer and I'll accept it as best answer – Pete Marise Feb 26 '23 at 00:01

1 Answers1

1

If you send a long string to the Immediate pane (or a series of shorter strings) using Debug.Print, you're only going to see the last 200 lines or so: that's a built-in limit when using the Immediate pane.
Msgbox would show the beginning of the content (the max size of msgbox content is approx. 1024 characters). Max. length in a cell is about 32k characters.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125