1

I'm trying to download the QR code for my products using googleapis.com, I'm using this code in the Modules called: modHtthGet:

Public Sub httpGet(sourcePath As String, destinationPath As String)

Dim xmlHTTP
Dim contents
Dim oStr

Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
xmlHTTP.Open "GET", sourcePath, False
xmlHTTP.Send
contents = xmlHTTP.ResponseBody

Set oStr = CreateObject("ADODB.Stream")
oStr.Mode = adModeReadWrite
oStr.Type = adTypeBinary
oStr.Open

oStr.Write (contents)
oStr.SaveToFile destinationPath, adSaveCreateOverwrite

End Sub

then I call it from my form using the code:

Private Sub Command53_Click()

httpGet "https://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=L&chl=" & 
Me.Pro, _
"C:\FolderToDownload\" & Me.Product_Code & ".jpg"

End Sub

that will download the QR code to the folder, all goes fine but if the Product_code in Arabic characters then I get an empty or wrong QR code

I tried many way to resolve the problem but cannot, I hope someone can help..

Thanks n advance

braX
  • 11,506
  • 5
  • 20
  • 33
Scents
  • 11
  • 1
  • You can't just throw unicode characters in URLs, encode them using the approach specified there. – Erik A Dec 21 '21 at 10:58
  • By default, North American versions of MS Office don't support extended unicode characters in the VBA editor, however I think it's straightforward to change the locale (in Windows settings).. See [this](https://www.spreadsheet1.com/how-to-display-foreign-characters-in-vbe.html) and [this](https://social.msdn.microsoft.com/Forums/en-US/78eeab51-f39e-423c-8afc-ebd218d658c3/how-to-make-vba-to-read-and-understand-characters-in-other-keyboard-language?forum=isvvba) and [this](https://www.mrexcel.com/board/threads/unicode-characters-in-vba-editor.351799/) and similar Google'd info – ashleedawg Dec 21 '21 at 11:29
  • URL's *can* have Unicode characters in them, under certain TLD's (currently `.cf .fm .ga .gq .kz .ml .st .tk .to .uz .ws`). Example: [https://i.ws](https://i.ws) .... they may indeed need to be encoded but it's not standard URL encoding... See [emoji domains](https://en.wikipedia.org/wiki/Emoji_domain) and [**Punycode**](https://en.wikipedia.org/wiki/Punycode). – ashleedawg Dec 21 '21 at 11:34
  • @ashleedawg My entire point is they must be encoded and I've linked it. Punycode is only for the hostname so not valid here, the valid approach is percent encoding as I've linked. Browsers do the encoding for you nowadays, but you get no such luxury when working with XMLHTTP objects. – Erik A Dec 21 '21 at 12:11

0 Answers0