Discussion:
WriteLine fails with error 5 (bad argument) on a string ?
(too old to reply)
R.Wieser
2017-04-18 12:14:27 UTC
Permalink
Hello all,

Partially a "gotcha" story, partially a question. Here goes:

I've retrieved a webpages content using the XMLHTTP object, and than
attempted to write the "responseText" result into a file. Easy enough, just
use "<fileobject>.write <httpobject>.responseText" you would say. I would
too.

But for some unfathomable reason it (sometimes) fails with an err.number of
5 ....

After quite a bit of head-scratching and testing it turns out there are
characters in that response that Write(Line) cannot handle*, and it barfs.
Funny thing is that wscript.echo has absolutily no problem with putting the
string onto the screen though (so why the difference?).


*Which char can't it handle ? Good question. I copied all characters
between " " and "~" as well as bCR and vbLF to another string (which was
succesfully written to the file!), and displayed both the remaining symbols
as well as their ASCII values. It apeared that its the the char "?" with
ASCII code 63 thats causing the problems.

Whoa, wait! Isn't that char between " " (32) and "~" (126) ? Yup, it
is. :-)

So, what is going on ? I take it its VBScript and its conversion of
wide-string chars to ASCII thats playing peek-a-boo with us: the "?" is the
default replacement character for any wide-character it cannot convert into
an equivalent ASCII character.

So, how do I figure out which (wide-)char is actually the problem (I take it
all are, but just for the sake of argument) ? Thats a problem: I can't get
its value, and I can't write it to file either (and than check it with some
other program). A nice catch22, ain't it :-D

tl;dr:
How do I get a fileobject to write a string to file regardless of the
combination of bytes in it (write it as a multi-byte string) ?

Bonus question (for when the first is impossible): How do I convert a string
into one I can actually write to a file WITHOUT having to go thru it
byte-by-byte (copy the aceptable ones into a new string and write that one)
? I've already tried CStr and Trim, but neither are helpfull. :-\

Regards,
Rudy Wieser
Mayayana
2017-04-18 13:06:50 UTC
Permalink
Lots of gotchas with UTF-8. For what it's worth, you
can look here:

http://www.jsware.net/jsware/scrfiles.php5#u2a

It's 3 different methods of converting between UTF-8
and ANSI.

In general a page that's UTF-8 should say so in a
META charset tag, which will at least help to reduce
the work. Unfortunately, it's become politically
correct to use UTF-8 even where it's not needed.
Microsoft pagesare a good example. They use UTF-8
characters for curly quotes and spaces, neither of
which is necessary. It makes a mess when trying to
save their pages.
R.Wieser
2017-04-18 14:44:40 UTC
Permalink
Mayayana,
Post by Mayayana
Lots of gotchas with UTF-8. For what it's worth,
Thanks for that link.

There seems to be a problem though: my own tries to extract a single byte
from a string seem to show that that isn't possible. Also, trying to get
the value of the retrieved (unicode) character (using "asc(...)" shows I get
an already-converted value, not the origional unicode one.

For a moment I was flabbergasted: how come that code works using the same
method as I was using in my script ("mid( )" followed by "asc( )") and mine
has problems and his doesn't. But than I realized that that most likely
has to do with his script reading the file as if its ASCII, thereby breaking
up the multiple bytes of a multibyte char, storing them as seperate chars.

In other words: another catch 22 : I could parse the "responseText" string
contents if I would first write them to a file and than read it back as
ASCII, but than I would first need to be able to write it to a file* ... :-D

As for the conversion itself ? I do not really want to have it converted
to ASCII, but just to a format which will be acceptable to Write /
WriteLine, allowing me to write an exact copy of what is retrieved from the
website to file.

Regards,
Rudy Wieser
Post by Mayayana
Lots of gotchas with UTF-8. For what it's worth, you
http://www.jsware.net/jsware/scrfiles.php5#u2a
It's 3 different methods of converting between UTF-8
and ANSI.
In general a page that's UTF-8 should say so in a
META charset tag, which will at least help to reduce
the work. Unfortunately, it's become politically
correct to use UTF-8 even where it's not needed.
Microsoft pagesare a good example. They use UTF-8
characters for curly quotes and spaces, neither of
which is necessary. It makes a mess when trying to
save their pages.
Mayayana
2017-04-18 22:50:41 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| As for the conversion itself ? I do not really want to have it converted
| to ASCII, but just to a format which will be acceptable to Write /
| WriteLine, allowing me to write an exact copy of what is retrieved from
the
| website to file.

I don't understand why it's not working. As long as
there are no nulls it should be writable. WSH is not
really writing ASCII. It's writing ANSI. As far as I know
it doesn't recognize UTF-8, so I would think it should
write the string normally as ANSI in accord with your
codepage.

Either way, if you write UTF-8 to disk you'll need
to read it as UTF-8. But I don't find any problem
writing high characters. If I write the UTF-8 marker,
239-187-191 in a string it works. If I write it at
the front of a string it disappears when opened in
notepad, as expected. In both cases it writes fine.
R.Wieser
2017-04-19 09:39:47 UTC
Permalink
Mayayana,
Post by Mayayana
I don't understand why it's not working.
The problem is that it cannot write an unicode* character (anything with an
"ascii-code" larger than 255) to simple, ASCII-style file.

*wrong, not really specific, name, see below.
Post by Mayayana
As long as there are no nulls it should be writable.
Variant strings are length-counted, and cause no problem when you try to
write embedded NULs to a file (been there, done that).
Post by Mayayana
Either way, if you write UTF-8 to disk you'll need
to read it as UTF-8.
The problem is that I need to write it to file first (the "read it" part
might in my case well not been done by VBS). :-)
Post by Mayayana
If I write the UTF-8 marker, 239-187-191 in a string it works
That is because you're still writing (extended) ASCII, embedding
*multi-byte* characters.

And checking the 'Web just now (googeling "unicode vs wide-character"), I
see I made a mistake: I've been referring to the way VBScript stores its
strings as being "unicode", when infact its using "wide character" (aka: all
chars are of the same size, in this case 16 bits).

When you try to write a wide-character with a codepoint larger than 255 to
an ASCII-style file it simply barfs (even though it has no problems with
"wscript.echo"-ing the string!).

And alas, the webpage thats retrieved seems to contain a few multi-byte
characters *which get converted into wide-characters* and stored as such in
the string ...

And, as it turns out, applying "asc( )" on a wide-character symbol does not
return its codepoint, but it gets converted to ASCII first, and as such
returns the default "cannot convert" replacement-characters value: 63 (the
questionmark).

Regards,
Rudy Wieser
Post by Mayayana
| As for the conversion itself ? I do not really want to have it converted
| to ASCII, but just to a format which will be acceptable to Write /
| WriteLine, allowing me to write an exact copy of what is retrieved from
the
| website to file.
I don't understand why it's not working. As long as
there are no nulls it should be writable. WSH is not
really writing ASCII. It's writing ANSI. As far as I know
it doesn't recognize UTF-8, so I would think it should
write the string normally as ANSI in accord with your
codepage.
Either way, if you write UTF-8 to disk you'll need
to read it as UTF-8. But I don't find any problem
writing high characters. If I write the UTF-8 marker,
239-187-191 in a string it works. If I write it at
the front of a string it disappears when opened in
notepad, as expected. In both cases it writes fine.
Mayayana
2017-04-19 13:22:24 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| And checking the 'Web just now (googeling "unicode vs wide-character"), I
| see I made a mistake: I've been referring to the way VBScript stores its
| strings as being "unicode", when infact its using "wide character" (aka:
all
| chars are of the same size, in this case 16 bits).
|
I think it's getting confused. VBS deals with ASCII
or unicode-16, which is 2 bytes per character. What
VBS is really dealing with is ANSI. 1 byte per
character, with 128+ interpeted according to the
local codepage. UTF-8 is unicode, but it's written
as a kind of ANSI multi-byte encoding. 1-4 bytes
can identify a charcter, but those bytres are
interpreted one at a time. While U-16 is a series of
2-byte characters (usually with a null as the sceond
byte), U-8 is readable as ANSI. There might be 3
bytes to signify a curly quote when read as U-8,
but those same 3 bytes also translate to 3 characters
in ANSI. That's why I don't see how it could be a
problem to read the string unless there are embedded
nulls. (Yes, I know VBS can deal with nulls, but as
you probably know, it takes some care to make it
work.)


| When you try to write a wide-character with a codepoint larger than 255 to
| an ASCII-style file it simply barfs (even though it has no problems with
| "wscript.echo"-ing the string!).
|
Yes, but that's U-16. How are you getting U-16
responses? Maybe there's a setting wrong? If it's
U-8 then there's no codepoint "larger than 255".
There are only multi-byte characters. (See above.)

| And alas, the webpage thats retrieved seems to contain a few multi-byte
| characters *which get converted into wide-characters* and stored as such
in
| the string ...
|
This isn't making sense. By multibyte you seem
to mean U-16. You can't have a few U-16
characters. Either it's unicode or it's ANSI, as far
as VBS is concerned. If it's ANSI that might be
UTF-8, but it's still digestible as ANSI. It's still
a series of non-null bytes.

| And, as it turns out, applying "asc( )" on a wide-character symbol does
not
| return its codepoint, but it gets converted to ASCII first, and as such
| returns the default "cannot convert" replacement-characters value: 63 (the
| questionmark).
|

AscW. Asc returns the first byte. (Unicode is
big-endian.) You can't mix and match in VBS. Either
you're working in unicode or you're working in ANSI.
R.Wieser
2017-04-19 15:27:13 UTC
Permalink
Mayayana,
What VBS is really dealing with is ANSI.
Really ? Than how is it that every fucking string variant needs to have
its contents back-converted from WideChar to MultiByte (the next-best thing
to ASCII) whenever I need to use it myself ?

In other words: My experiences with the VBS engine (and COM/OCX/ActiveX
objects) are rather different.
Yes, but that's U-16. How are you getting U-16
responses? Maybe there's a setting wrong?
I already told you what exactly I'm trying to write to the file. I'm not
going to repeat that at-nauseum. As for settings ? You tell me. I'm
not aware of *any* settings in that regard.
U-8 then there's no codepoint "larger than 255".
There are only multi-byte characters. (See above.)
Than explain to me why the string does not want to get written to a simple
ASCII file.

As you might tell, I'm getting a bit tired from our fruitless to-and-fro.

I've mentioned (a few times now) why I think VBS refuses to write the
string, but you do not want to have that true. But neither do you come with
any other explanation to why it could happen.

Furthermore, although I've mentioned several times that I've displayed all
characters outside the ASCII range and *still* are getting a questionmark
(ASCII code 63) there you've not even responded to that odity -- an oddity
which I've mentioned I find rather telling.

If you have nothing more to add than I think we should stop here.

I realize that you're trying to help, but you're not actually doing that.
Sorry.

Regards,
Rudy Wieser
| And checking the 'Web just now (googeling "unicode vs wide-character"), I
| see I made a mistake: I've been referring to the way VBScript stores its
all
| chars are of the same size, in this case 16 bits).
|
I think it's getting confused. VBS deals with ASCII
or unicode-16, which is 2 bytes per character. What
VBS is really dealing with is ANSI. 1 byte per
character, with 128+ interpeted according to the
local codepage. UTF-8 is unicode, but it's written
as a kind of ANSI multi-byte encoding. 1-4 bytes
can identify a charcter, but those bytres are
interpreted one at a time. While U-16 is a series of
2-byte characters (usually with a null as the sceond
byte), U-8 is readable as ANSI. There might be 3
bytes to signify a curly quote when read as U-8,
but those same 3 bytes also translate to 3 characters
in ANSI. That's why I don't see how it could be a
problem to read the string unless there are embedded
nulls. (Yes, I know VBS can deal with nulls, but as
you probably know, it takes some care to make it
work.)
| When you try to write a wide-character with a codepoint larger than 255 to
| an ASCII-style file it simply barfs (even though it has no problems with
| "wscript.echo"-ing the string!).
|
Yes, but that's U-16. How are you getting U-16
responses? Maybe there's a setting wrong? If it's
U-8 then there's no codepoint "larger than 255".
There are only multi-byte characters. (See above.)
| And alas, the webpage thats retrieved seems to contain a few multi-byte
| characters *which get converted into wide-characters* and stored as such
in
| the string ...
|
This isn't making sense. By multibyte you seem
to mean U-16. You can't have a few U-16
characters. Either it's unicode or it's ANSI, as far
as VBS is concerned. If it's ANSI that might be
UTF-8, but it's still digestible as ANSI. It's still
a series of non-null bytes.
| And, as it turns out, applying "asc( )" on a wide-character symbol does
not
| return its codepoint, but it gets converted to ASCII first, and as such
| returns the default "cannot convert" replacement-characters value: 63 (the
| questionmark).
|
AscW. Asc returns the first byte. (Unicode is
big-endian.) You can't mix and match in VBS. Either
you're working in unicode or you're working in ANSI.
Mayayana
2017-04-19 17:49:51 UTC
Permalink
We don't seem to be communicating. Maybe I'm
making wrong assumptions. You haven't posted
any code, so it's hard to know. My assumption is
that you're using FSO and CreateTextFile.

The docs say ResponseText "tries to make a
unicode string out of what it gets and assumes
utf-8." That's ambiguous because unicode (wideChar)
is 2-byte characters while UTF-8 is a hack to fit
unicode into ANSI text. All non-wideChar is "multibyte"
(An unfortunate misnomer. It should be single-byte)
and differs only in the way it's interpreted. For instance:

E2 99 A5

In UTF-8 that's a heart. In English ANSI it's
⠙ ¥ (a with caret, trademark, Yen symbol)
With a Russian codepage it might be 3 standard
Russian characters. However it's interpreted, it
works as ANSI because there are no nulls. It's
interpreted in terms of bytes rather than 2-byte
integers.

So either you have UTF-16, which you'll need to
write as unicode and/or convert, or you have single
byte text that will write to disk as ANSI. (WSH says
ASCII, but it's not actually ASCII. It's 8-bit ANSI.)

UTF-8 and UTF-16 are both unicode, but in entirely
different ways. I was figuring you must have one
or the other. If it's really UTF-8 then it will write (albeit
with corruption) as ANSI. If it's really UTF-16 then it
should write if you create the file as unicode. (That's
the option I was referring to. The third parameter of
CreateTextFile.) I was further assuming that you would
have tested those possibilities.

If you then want to switch unicode to ANSI
you can use the script I linked:

'-- write unicode version to disk.
Set TS = FSO.CreateTextFile(sFilU, True, True)
TS.Write s2
TS.Close
Set TS = Nothing

Set TS = FSO.OpenTextFile(sFilU, 1, False, -2)
Set TS2 = FSO.CreateTextFile(sFil, True, False)

Do
s3 = TS.ReadLine
TS2.WriteLine s3
Loop Until TS.AtEndOfStream

TS.Close
TS2.close
Set TS = Nothing
Set TS2 = Nothing
'--------------------------

Or you can load it into an array and drop out
each second byte.
R.Wieser
2017-04-20 15:56:11 UTC
Permalink
Mayayana,
Post by Mayayana
We don't seem to be communicating.
I thought we (somewhat) where, but we're again-and-again returning to the
"but it should be able to be written to an ANSI file" stance, when that is
exactly the problem I began with. :-(
Post by Mayayana
You haven't posted any code, so it's hard to know.
My assumption is that you're using FSO and CreateTextFile.
Yes. (but does that matter ?)

From the top of my initial post:

[quote]
I've retrieved a webpages content using the XMLHTTP object, and than
attempted to write the "responseText" result into a file. Easy enough, just
use "<fileobject>.write <httpobject>.responseText"
[/quote]

I assumed that that was all that was needed to know which objects where
involved.

Later on I also (several times) mentioned (in response to the suggestion of
using other objects) that I'm on an older system, which rather limits the
available objects.

Also, a few post back I mentioned:
[quote]
But if its so simple, whats than wrong with using the
Scripting.FileSystemObject objects CreateTextFile ?
[/quote]

But, as everything in that direction has failed, here are the (six!)
relevant lines:

[code]
set oHttp = CreateObject("Microsoft.XMLHTTP")
oHttp.open "GET", sURL, FALSE
oHttp.send ""
Set oFile = oFS.CreateTextFile(sTrgFile,true)
oFile.WriteLine oHttp.responseText
Set oFile=nothing
[/code]
Post by Mayayana
'-- write unicode version to disk.
Set TS = FSO.CreateTextFile(sFilU, True, True)
TS.Write s2
TS.Close
Set TS = Nothing
Why would I want to do that ? Only to read it back in as an ANSI string
and than work my way thru each of the byte-pairs ?

I thought I had made clear that I already could do that by walking over the
initial "responseText" variable -- and that I was looking for something
that did not need that approach.

The only thing I bumped into there was that, when filtered out the ASCII
range and used I used "asc( )" on remaining "mid(str,pos,1)" result, I got a
mangled value back (always 63) instead of the codepoint.

And why I did not try to solve that mangeled value problem ? Well, that I
explained at the bottom of my initial post:

[quote]
Bonus question (for when the first is impossible): How do I convert a
string into one I can actually write to a file WITHOUT having to go thru
it byte-by-byte (copy the aceptable ones into a new string and write that
one) ?
[/quote]
(please do notice the word written in all capitals!)

By the way, the "mangled codepoint" problem turned out easy to solve -- if
you know what to look for: the whole "trick" is to use "ascW( )" instead of
just "asc( )".

So, I can (now) go-and-check for all characters in that wide-character
string, and "replace" them with whatever I want to use instead. As long as
the replacements are ASCII/ANSI(?) ofcourse, otherwise the string will throw
the same error. :-)

BUT THATS NOT WHAT I WAS OUT FOR.

I simply wanted to 3) know why VBScript was not able to write a text it has
just read itself 2) if there was an internal method to convert the
unacceptable string to an acceptable one JUST LIKE WSCRIPT.ECHO SEEMS TO BE
ABLE TO DO*, or 1) how to tell VBScript to write the string exactly as it
read it thru the HTTPXML object (and which was delivered as UTF8
(multibyte) ).

... which I thought was all mentioned in my initial post ....

*and I did put that in full caps as I have not seen you respond to that in
any way ....

Instead I've been having a few rounds of sparring with you, as no matter
what I said you simply did not seem to understand most of what I said, no
matter how hard I tried. Why ? How ? No idea. Frustrating ?
Youbetya! :-((

Regards,
Rudy Wieser

P.s.
If you want to replicate the error I started with, just try to write a
"chrw(-257)" to a ASCII/ANSI-mode file (notice the "w" between the "chr",
and the "(" ).
Post by Mayayana
We don't seem to be communicating. Maybe I'm
making wrong assumptions. You haven't posted
any code, so it's hard to know. My assumption is
that you're using FSO and CreateTextFile.
The docs say ResponseText "tries to make a
unicode string out of what it gets and assumes
utf-8." That's ambiguous because unicode (wideChar)
is 2-byte characters while UTF-8 is a hack to fit
unicode into ANSI text. All non-wideChar is "multibyte"
(An unfortunate misnomer. It should be single-byte)
E2 99 A5
In UTF-8 that's a heart. In English ANSI it's
â T ¥ (a with caret, trademark, Yen symbol)
With a Russian codepage it might be 3 standard
Russian characters. However it's interpreted, it
works as ANSI because there are no nulls. It's
interpreted in terms of bytes rather than 2-byte
integers.
So either you have UTF-16, which you'll need to
write as unicode and/or convert, or you have single
byte text that will write to disk as ANSI. (WSH says
ASCII, but it's not actually ASCII. It's 8-bit ANSI.)
UTF-8 and UTF-16 are both unicode, but in entirely
different ways. I was figuring you must have one
or the other. If it's really UTF-8 then it will write (albeit
with corruption) as ANSI. If it's really UTF-16 then it
should write if you create the file as unicode. (That's
the option I was referring to. The third parameter of
CreateTextFile.) I was further assuming that you would
have tested those possibilities.
If you then want to switch unicode to ANSI
'-- write unicode version to disk.
Set TS = FSO.CreateTextFile(sFilU, True, True)
TS.Write s2
TS.Close
Set TS = Nothing
Set TS = FSO.OpenTextFile(sFilU, 1, False, -2)
Set TS2 = FSO.CreateTextFile(sFil, True, False)
Do
s3 = TS.ReadLine
TS2.WriteLine s3
Loop Until TS.AtEndOfStream
TS.Close
TS2.close
Set TS = Nothing
Set TS2 = Nothing
'--------------------------
Or you can load it into an array and drop out
each second byte.
Mayayana
2017-04-20 17:24:28 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| If you want to replicate the error I started with, just try to write a
| "chrw(-257)" to a ASCII/ANSI-mode file (notice the "w" between the "chr",
| and the "(" ).
|

I assume you mean ChrW(257), since -257 is
meaningless. It writes to disk just fine if written
as unicode, with CreateTextFile(path, True, True)

| I thought I had made clear that I already could do that by walking over
the
| initial "responseText" variable -- and that I was looking for something
| that did not need that approach.

So this whole tantrum has been about your simply
refusing to accept that you can't write unicode to
disk as ANSI? I know you like to suffer in order to
cultivate irritation, but you could, maybe, find a
more productive issue. Why not tear your hair out
about something worth doing? :)

Good luck. Hopefully this discussion of character
encoding will be of at least some use to someone.
Ulrich Möller
2017-04-20 23:05:10 UTC
Permalink
Hi Mayayana,
Post by Mayayana
| If you want to replicate the error I started with, just try to write a
| "chrw(-257)" to a ASCII/ANSI-mode file (notice the "w" between the "chr",
| and the "(" ).
|
I assume you mean ChrW(257), since -257 is
meaningless. It writes to disk just fine if written
as unicode, with CreateTextFile(path, True, True)
ChrW(-257) is not meaningless! It is unicode u+FEFF which may be used
for detecting the current byte order.

see http://www.fileformat.info/info/unicode/char/FEFF/index.htm

Ulrich
Mayayana
2017-04-21 01:42:36 UTC
Permalink
"Ulrich Möller" <***@arcor.de> wrote


| ChrW(-257) is not meaningless! It is unicode u+FEFF which may be used
| for detecting the current byte order.
|
| see http://www.fileformat.info/info/unicode/char/FEFF/index.htm
|

FEFF is decimal 65279. Unicode numbers are not
signed. -257 is FFFFFEFF, outside the unicode range.
But what does it matter? Even if it were FEFF, why
would one write that to disk in order to test a
unicode write?

I'd assumed he was just trying to write something
above 255, to see if it works. And it works fine, as
long as one writes the file as unicode. He seemed to imply
that it causes some kind of error. Writing ChrW(257)
writes FF FE 01 01 as expected and gives me an "a"
with a line over it. Writing -257 gives me a file with
bytes FF FE FF FE. I'm guessing that may be the result
of trying to write an invalid character. The file just
ends up blank with two unicode markers. But I
don't know... And who cares?
R.Wieser
2017-04-21 08:11:46 UTC
Permalink
Mayayana,
Post by Mayayana
FEFF is decimal 65279.
Now try to subtract 65536 from that last number. What do you get ?
Coincidence ? I think not. :-)
Post by Mayayana
Unicode numbers are not signed
Nope, they are not. But how does that matter ? Also, you obviously have
no problem with translating from a decimal representation to a hexadecimal
one, but are incapable of converting an unsigned numbers representation (of
a specific bitcount !) to its signed counterpart ? Really ?
Post by Mayayana
-257 is FFFFFEFF
Why are you suddenly converting to a 32-bit representation ?

Try converting to a 16-bit representation -- after all, we where talking
about WideChars, which are just 16 bits -- and compare the result to the
very first hexadecimal value in your post. Coincidence ? Again, I think
not.

And by it you have proven for yourself that -256, FEFF and 65279 are just
*representations* of the same 16-bit value (that doesn't even exists/isn't
stored in either of those forms!)

God man, this is basic knowledge. What have you been doing all this time ?
Post by Mayayana
Writing -257 gives me a file with bytes FF FE FF FE.
So a negative value *does* work. Thanks for confirming that I guess. :-)

My file ends up containing FE FF 63 FF

(funny that 63. I could swear that I've seen it before .. :-) )
Post by Mayayana
I'm guessing that may be the result of trying to write an
invalid character.
And there it ends for you ? No urge to see what you would get when you
write another char ? I could not stop myself from placing a couple of
chrw(1)-s around the chrw(-257), wrote the 3-char string and took a peek at
the result. It was rather educational.

Regards,
Rudy Wieser
Post by Mayayana
| ChrW(-257) is not meaningless! It is unicode u+FEFF which may be used
| for detecting the current byte order.
|
| see http://www.fileformat.info/info/unicode/char/FEFF/index.htm
|
FEFF is decimal 65279. Unicode numbers are not
signed. -257 is FFFFFEFF, outside the unicode range.
But what does it matter? Even if it were FEFF, why
would one write that to disk in order to test a
unicode write?
I'd assumed he was just trying to write something
above 255, to see if it works. And it works fine, as
long as one writes the file as unicode. He seemed to imply
that it causes some kind of error. Writing ChrW(257)
writes FF FE 01 01 as expected and gives me an "a"
with a line over it. Writing -257 gives me a file with
bytes FF FE FF FE. I'm guessing that may be the result
of trying to write an invalid character. The file just
ends up blank with two unicode markers. But I
don't know... And who cares?
R.Wieser
2017-04-21 07:23:33 UTC
Permalink
Mayayana,
Post by Mayayana
I assume you mean ChrW(257), since -257 is
meaningless.
And I guess you did not (bother) to try :-(((

Also, -257 is simpy a signed-value-only systems way of displaying of a very
high unsigned value. Didn't you know that ?
Post by Mayayana
So this whole tantrum has been about your simply
refusing to accept that you can't write unicode to
disk as ANSI?
No. As I've tried to tell you several times now, its about a system which
can read UTF8 encoded strings, but than is incapable of writing the data to
disk in the same format as it read it (what the f*ck ?).

And again here we are: Me trying to explain either very basic stuff that
should be rather known (signed versus unsigned values, and how they in their
internal representation fully overlap) and repeating explanations which I
have not had _any_ feedback to that you even read them, let alone understood
them.

Did I already say that that is frustrating ? Talking to an intelligent
being while not being able to reach him ? It is. *Very* frustrating.
Post by Mayayana
I know you like to suffer in order to cultivate irritation, but you
could, maybe, find a more productive issue.
If your stance is _not_ to try to figure out if something that, logically
speaking, should be there*, but just go for a convoluted** work-around
instead than I would not want to see you writing commercial software. :-(

*and that is actually all I was out for: did I overlook / was I unaware of a
method or setting which would allow me to write the string as it was read.

**and pardon me, but you both ignored that I _didn't want_ to go the
convoluted way, _and_ you tried to make it even more, and rather
unnecessarily as it turns out, convoluted. :-(

So, here we are. At the end of another fruitless bout of wasting our time
... And I even had my hopes up that this time it would work.
Post by Mayayana
Good luck.
Thanks, but I would rather speak with someone who knows something about
VBScripts objects (below the level of just stringing commands together). :-)


Regards,
Rudy Wieser
Post by Mayayana
| If you want to replicate the error I started with, just try to write a
| "chrw(-257)" to a ASCII/ANSI-mode file (notice the "w" between the "chr",
| and the "(" ).
I assume you mean ChrW(257), since -257 is
meaningless. It writes to disk just fine if written
as unicode, with CreateTextFile(path, True, True)
| I thought I had made clear that I already could do that by walking over
the
| initial "responseText" variable -- and that I was looking for something
| that did not need that approach.
So this whole tantrum has been about your simply
refusing to accept that you can't write unicode to
disk as ANSI? I know you like to suffer in order to
cultivate irritation, but you could, maybe, find a
more productive issue. Why not tear your hair out
about something worth doing? :)
Good luck. Hopefully this discussion of character
encoding will be of at least some use to someone.
Mayayana
2017-04-18 13:57:57 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| I've retrieved a webpages content using the XMLHTTP object, and than
| attempted to write the "responseText" result into a file.

Out of curiosity.... Have you used WinHttpRequest?
I've never used xmlhttp and don't know anything about it.
Since it seems to be part of IE I don't think I'd want
to use it.
In the past I've avoided API functions like UrlDownloadToFile
that are really just IE calls. It seems very sloppy to me,
writing software that leaves records in IE history and cache,
and may be affected by IE settings.
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
R.Wieser
2017-04-18 15:20:38 UTC
Permalink
Mayayana,
Post by Mayayana
Out of curiosity.... Have you used WinHttpRequest?
Nope. I have also tried to use it, but it doesn't exist on the machine I'm
scripting on (its rather old).
Post by Mayayana
I've never used xmlhttp and don't know anything about it.
Since it seems to be part of IE I don't think I'd want
to use it.
And you think WinHttpRequest *isn't* part of IE ? I would not bet on that
if I where you. :-) IE is just a rather thin shell over a lot of
components that are an integral part of Windows.
Post by Mayayana
In the past I've avoided API functions like UrlDownloadToFile
that are really just IE calls
I think you would make a rather safe assumption in that both XMLHTTP as well
as WinHttpRequest use its direct sibbling (downloading the data to memory),
just with a bit different packaging.
Post by Mayayana
So some years ago I wrote winsock code for Interet functions
Yup, same here. But I wanted to see if I could get something to work by
using run-of-the-mill stuff, instead of trying to build/fix everything
myself. Alas, VBScript still has the "everything *must* be Unicode"
blight of yesteryear, and that doesn't make it easier.

Heck, currently my whole problem is caused by VBScript converting MultiByte
data into its internal Unicode representation, and than not being able to
convert it back to MultiByte again ... :-(

Regards,
Rudy Wieser
Post by Mayayana
| I've retrieved a webpages content using the XMLHTTP object, and than
| attempted to write the "responseText" result into a file.
Out of curiosity.... Have you used WinHttpRequest?
I've never used xmlhttp and don't know anything about it.
Since it seems to be part of IE I don't think I'd want
to use it.
In the past I've avoided API functions like UrlDownloadToFile
that are really just IE calls. It seems very sloppy to me,
writing software that leaves records in IE history and cache,
and may be affected by IE settings.
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
Mayayana
2017-04-18 18:27:33 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| Nope. I have also tried to use it, but it doesn't exist on the machine
I'm
| scripting on (its rather old).
|
Yes. XP+.

| And you think WinHttpRequest *isn't* part of IE ?

Yes. I checked it out.
R.Wieser
2017-04-18 20:15:37 UTC
Permalink
Mayayana,
Post by Mayayana
| And you think WinHttpRequest *isn't* part of IE ?
Yes. I checked it out.
If you mean that (you read that) it isn't a part of the wrapper that
combines all kinds of OS build-in stuff to be able to show you "IE, the
browser", than you're (probably) right.

If you mean that its isn't part of "the neccesary IE parts inside the OS
that *cannot* be removed, otherwise the OS will not be able to perfor all
its tasks" (the words of the thanwhile head-honcho of MS, not mine), than
you are mistaken.

Yes, MS was forced to remove the *browser* from certain versions of its OS
(can't exactly remember which ones). That didn't mean that MS wanted, nor
could remove all the IE related crap outof the OS (the "can't do it" was in
that time the center of many a "are they pulling us a fast one?"
conversation).

For example, did you know that you can search the web by entering a series
of words into the *file*browser (windows explorer) addresbar that do not
resemble an existing path or file ? Annoys me to not end (apart from being
a security leak issue) ...

Regards,
Rudy Wieser
Post by Mayayana
| Nope. I have also tried to use it, but it doesn't exist on the machine
I'm
| scripting on (its rather old).
|
Yes. XP+.
| And you think WinHttpRequest *isn't* part of IE ?
Yes. I checked it out.
Mayayana
2017-04-18 22:30:40 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| > | And you think WinHttpRequest *isn't* part of IE ?
| >
| > Yes. I checked it out.
|
| If you mean that (you read that) it isn't a part of the wrapper that
| combines all kinds of OS build-in stuff to be able to show you "IE, the
| browser", than you're (probably) right.
|
| If you mean that its isn't part of "the neccesary IE parts inside the OS
| that *cannot* be removed, otherwise the OS will not be able to perfor all
| its tasks" (the words of the thanwhile head-honcho of MS, not mine), than
| you are mistaken.

I mean it's not connected to IE. The IE operations
are connected with wininet.dll and urlmon.dll. Winhttp
uses neither. If you check Depends you'll see it uses
a few string parsing functions from shlwapi.dll, but aside
from that it's all basic system stuff. And it doesn't add
to cache or history. You can check it out for yourself.

It may be they released it to provide a basic file
download component that would be clean. I don't
know. But after checking it out I decided to start
using to instead of my winsock code.

But it does require WinXP+.
R.Wieser
2017-04-19 09:09:38 UTC
Permalink
Mayayana,
Post by Mayayana
I mean it's not connected to IE.
Look at it from the other direction: IE is (heavily) dependant on a number
of OS-provided items. Items that are also used by the OS itself.
Post by Mayayana
If you check Depends you'll see it uses a few string parsing
functions from shlwapi.dll, but aside from that it's all basic
system stuff
You're joking, right ? If that is *all* it uses it *cannot* make a
network connection *ever*. But as it does ...
Post by Mayayana
You can check it out for yourself.
Thanks. I just did. Alas, working thru the whole program figuring out what
it does and how it connects to the 'web would take me quite a bit more time
(if I ever can get thru all of it).

Granted, on first sight it doesn't look as if its directly handing off its
work to either of those two DLLs you mentioned.
Post by Mayayana
But it does require WinXP+.
Yep, that would be a problem ...

Regards,
Rudy Wieser
Post by Mayayana
| > | And you think WinHttpRequest *isn't* part of IE ?
| >
| > Yes. I checked it out.
|
| If you mean that (you read that) it isn't a part of the wrapper that
| combines all kinds of OS build-in stuff to be able to show you "IE, the
| browser", than you're (probably) right.
|
| If you mean that its isn't part of "the neccesary IE parts inside the OS
| that *cannot* be removed, otherwise the OS will not be able to perfor all
| its tasks" (the words of the thanwhile head-honcho of MS, not mine), than
| you are mistaken.
I mean it's not connected to IE. The IE operations
are connected with wininet.dll and urlmon.dll. Winhttp
uses neither. If you check Depends you'll see it uses
a few string parsing functions from shlwapi.dll, but aside
from that it's all basic system stuff. And it doesn't add
to cache or history. You can check it out for yourself.
It may be they released it to provide a basic file
download component that would be clean. I don't
know. But after checking it out I decided to start
using to instead of my winsock code.
But it does require WinXP+.
Mayayana
2017-04-19 13:23:47 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| > But it does require WinXP+.
|
| Yep, that would be a problem ...

Welcome to the 20th century. :)
Mayayana
2017-04-19 13:59:15 UTC
Permalink
"R.Wieser" <***@not.available> wrote

| > If you check Depends you'll see it uses a few string parsing
| > functions from shlwapi.dll, but aside from that it's all basic
| > system stuff
|
| You're joking, right ? If that is *all* it uses it *cannot* make a
| network connection *ever*. But as it does ...
|

Good question.
Looking at the DLL as text, there seem to be a
lot of winsock error codes. I'm guessing it either
calls one of the winsock libs without linking, or
it incorporates winsock functionality. ws2_32.dll
is only 80 KB, so maybe Winhttp just incorporates
the whole thing -- sort of a winsock COM object.
R.Wieser
2017-04-19 15:41:39 UTC
Permalink
Mayayana,
Post by R.Wieser
Good question.
I'm guessing it either calls one of the winsock libs without linking
Dynamic loading. Rather possible, as it definitily uses LoadLibrary (from
Kernel32).
Post by R.Wieser
or it incorporates winsock functionality.
I would say thats quite a "duh!" :-)

The other possibility is that it simply does a static linking of the needed
libraries.

Although that is rather counter-productive, not needing to distribute any of
the IE related libraries (though, how IE is WS2_32 ?) would keep MS on the
good side of the thanwhile inspectors (that where there to make sure MS
would not try to sneak in IE anyway).

Regards,
Rudy Wieser
Post by R.Wieser
| > If you check Depends you'll see it uses a few string parsing
| > functions from shlwapi.dll, but aside from that it's all basic
| > system stuff
|
| You're joking, right ? If that is *all* it uses it *cannot* make a
| network connection *ever*. But as it does ...
Good question.
Looking at the DLL as text, there seem to be a
lot of winsock error codes. I'm guessing it either
calls one of the winsock libs without linking, or
it incorporates winsock functionality. ws2_32.dll
is only 80 KB, so maybe Winhttp just incorporates
the whole thing -- sort of a winsock COM object.
GS
2017-04-18 15:58:59 UTC
Permalink
Post by Mayayana
Post by R.Wieser
I've retrieved a webpages content using the XMLHTTP object, and than
attempted to write the "responseText" result into a file.
Out of curiosity.... Have you used WinHttpRequest?
I've never used xmlhttp and don't know anything about it.
Since it seems to be part of IE I don't think I'd want
to use it.
In the past I've avoided API functions like UrlDownloadToFile
that are really just IE calls. It seems very sloppy to me,
writing software that leaves records in IE history and cache,
and may be affected by IE settings.
Wow! I use this API but didn't know the IE part of it!
Post by Mayayana
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
Sounds worth looking into...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-26 13:56:45 UTC
Permalink
Post by Mayayana
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
I've been looking into this and have come up short on examples for how to
download files in place of using UrlDownloadToFile. Can you point me in the
right direction? (I've hit a situation where my app keeps getting the older
cache version of the file (Win10), not an updated version when my online form
submits new data to it!)
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
R.Wieser
2017-04-26 14:35:25 UTC
Permalink
GS

Plugging "UrlDownloadToFile cache" into Google yielded this (second result):

http://stackoverflow.com/questions/75432/how-can-i-prevent-urldownloadtofile
-from-retrieving-from-the-cache

Regards,
Rudy Wieser
Post by GS
Post by Mayayana
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
I've been looking into this and have come up short on examples for how to
download files in place of using UrlDownloadToFile. Can you point me in the
right direction? (I've hit a situation where my app keeps getting the older
cache version of the file (Win10), not an updated version when my online form
submits new data to it!)
--
Garry
Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-26 14:44:39 UTC
Permalink
Post by R.Wieser
GS
http://stackoverflow.com/questions/75432/how-can-i-prevent-urldownloadtofile
-from-retrieving-from-the-cache
Regards,
Rudy Wieser
Post by GS
Post by Mayayana
So some years ago I wrote winsock code for Interet functions.
But awhile back someone pointed me to WinHttpRequest.
It turns out to be a clean, simple way to make server requests,
without the sloppy IE tie-in. Some of the methods use strings
rather than variants, but it seems to work fine with VBScript.
(I've only used it in VB6, but I've seen VBS code.)
I've been looking into this and have come up short on examples for how to
download files in place of using UrlDownloadToFile. Can you point me in the
right direction? (I've hit a situation where my app keeps getting the older
cache version of the file (Win10), not an updated version when my online
form submits new data to it!)
--
Garry
Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Thanks, Rudy! I already did this but decided to explore possibly using
WinHttpRequest since it 'apparently' doesn't use caches...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-26 15:07:41 UTC
Permalink
"GS" <***@v.invalid> wrote

| I've been looking into this and have come up short on examples for how to
| download files in place of using UrlDownloadToFile. Can you point me in
the
| right direction? (I've hit a situation where my app keeps getting the
older
| cache version of the file (Win10), not an updated version when my online
form
| submits new data to it!)
|

I don't have time right now to pick apart
the code, but I'd be happy to send it to you
or clean it up later.

The calls are very simple, but there are a few
things to know. I ended up writing a function to
return error strings, which is handy. I also
have a function for setting options. There are
some details to know there. For instance, XP
doesn't support higher than TLS 1.0:

Private Sub TLSSetOptions(AllowSecurityErrors As Boolean)
On Error Resume Next
With WHR
.SetRequestHeader "Accept-Encoding", "gzip"
.SetRequestHeader "Host", sDefServer
.SetRequestHeader "User-Agent", UAgent
.Option(WinHttpRequestOption_UserAgentString) = UAgent 'useragent
If AllowSecurityErrors = False Then
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrIgnore
'ignore ssl errors
Else
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrDontIgnore
'don't ignore ssl errors
End If
.Option(WinHttpRequestOption_SecureProtocols) = OptTLS1_0 ' use TLS
1.0. 1.1 and 1.2 cause error in XP.
.Option(WinHttpRequestOption_EnablePassportAuthentication) = False
'block passport auth
.Option(WinHttpRequestOption_EnableCertificateRevocationCheck) = False
' block check of revoked certificate
End With
End Sub

The calling code is slightly enmeshed so I can't reprint
it here, but it's simple. I used it in this (link below), after
giving up on trying to do encryption from scratch over
winsock. It's far simpler than winsock, and I've found it
very dependable. There isn't quite so much control as
there is with winsock, but more than you get with
wininet:

http://www.jsware.net/jsware/gmapkit.php5

There was a discussion in the VB6 group at the time I
was working out this code.
I probably had the usual argument with Arne about how
he thought I was doing everything wrong and I thought
he was out to lunch and avoiding being helpful. :)
But those arguments at least have the benefit of airing
out the issues.
Mayayana
2017-04-26 20:29:10 UTC
Permalink
Garry,

See if this code makes sense. I had to pull it from my program
code in pieces, but I think it will be clear when you read it.
Note: I provide the option to accept gzip encoding. That
seems polite these days. I let the server know that in the header.
But that also means one has to be prepared to decode gzip.

Most of the error issues never happen in my use of winhttp,
but I wanted to write it to be as informative and flexible as
possible. So if the call fails to download a file I run the result
through my error parser and then may 1) show a message asking
how to proceed or 2) try the call again with lower security
restrictions.

Another note: XP can't handle TLS 1.1. Win7 can. If you
want to test OS version you can make that option more
flexible. But be careful. Vista/7 and later will lie about OS
version. If someone runs in XP mode you'll be told you're
running on XP. But that doesn't mean XP code will work
properly. I just settled for TLS 1.0 figuring that highest
security for Google maps is not critical.

At the end of the main function (which is in a UC) the
downloaded file is in a byte array and an event has been
raised to deal with it.

And without further ado, here's the code. Wordwrap is going
to be horrendous here. Sorry.....

'declares:
Private Const OptTLS1_0 As Long = &H80&

'-- these fail in XP -------------------
Private Const OptTLS1_1 As Long = &H200&
Private Const OptTLS1_2 As Long = &H800&
Private Const OptAnyTLS As Long = &HA80& 'OptTLS1_0 Or OptTLS1_1 Or
OptTLS1_2

Private Const OptErrIgnore As Long = &H3300&
Private Const OptErrDontIgnore As Long = &H0&


' code within function TLSGetImage to get a file.
' This doesn't need to be an image file. I just had
'reasons to deal with different files differently.
' I didn't include all of function here, but the gist
'of it should be clear.

If BooTLS = True Then
sFullURL = "Loading Image..."
Else
sFullURL = "Loading Image..."
End If
Set WHR = New WinHttpRequest
WHR.open "GET", sFullURL, False
TLSSetOptions True
Err.Clear
On Error Resume Next
WHR.Send
If Err.Number <> 0 Then
LRet = ProcessWNRError(Err.Number, ErrInt)
Select Case LRet
'-- return 0 if dealt with (and should quit)
'-- -1 to show winhttp error and quit,
'--1 for security options.
Case 0 'either didn't want to continue after cert error or already
showed error msg.
sErr = "Server error: " & CStr(ErrInt) & " - " &
Err.Description
Set WHR = Nothing
TLSGetImage = -1
GoTo FinishUp
Case -1
sErr = "Server error: " & CStr(ErrInt) & " - " &
Err.Description
MsgBox "Server error: " & CStr(ErrInt) & " - " &
Err.Description
Set WHR = Nothing
TLSGetImage = -1
GoTo FinishUp
Case Else ' 1
WHR.open "GET", sFullURL, False
TLSSetOptions False '--try again without security errors
blocking.
WHR.Send
End Select
End If

LServerCode = WHR.Status
sServerCode = CStr(LServerCode)

If LServerCode <> 200 Then
sErr = "Server error: " & sServerCode
If Err.Number <> 0 Then sErr = sErr & "Program error: " & Err.Number
& " - " & Err.Description
TLSGetImage = -2
Set WHR = Nothing
GoTo FinishUp
End If

sHeader1 = WHR.GetAllResponseHeaders
A1 = WHR.ResponseBody
Set WHR = Nothing
If InStr(sHeader1, "Content-Encoding") > 0 And InStr(sHeader1,
"gzip") > 0 Then
AFile = GUnzip2(A1, LRet)
If LRet <> 0 Then
sErr = "Unzip error: " & CStr(LRet)
TLSGetImage = -2
End If
Else
AFile = A1
End If

FinishUp:
RaiseEvent OnFinish(TLSGetImage, sErr)
'-function ends here----

Private Sub TLSSetOptions(AllowSecurityErrors As Boolean)
On Error Resume Next
With WHR
.SetRequestHeader "Accept-Encoding", "gzip"
.SetRequestHeader "Host", sDefServer '-- like www.somewhere.com
.SetRequestHeader "User-Agent", UAgent '-- like a browser UA, or allow
user to se it.
.Option(WinHttpRequestOption_UserAgentString) = UAgent 'useragent
If AllowSecurityErrors = False Then
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrIgnore
'ignore ssl errors
Else
.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = OptErrDontIgnore
'don't ignore ssl errors
End If
.Option(WinHttpRequestOption_SecureProtocols) = OptTLS1_0 ' use TLS
1.0. 1.1 and 1.2 cause

error in XP.
.Option(WinHttpRequestOption_EnablePassportAuthentication) = False
'block passport auth
.Option(WinHttpRequestOption_EnableCertificateRevocationCheck) = False
' block check of

revoked certificate
End With
End Sub

'------------------------------------------------------

'error parser code:

'-- return 0 if dealt with (and should quit), -1 to show winhttp error and
quit, 1 for security options.
Public Function ProcessWNRError(LErr As Long, IntError As Integer) As Long
Dim i3 As Integer
Dim LRet As Long
On Error Resume Next
i3 = GetLowInt(LErr)
Select Case i3
Case 12029 'Returned if connection to the server failed.
MsgBox "Unable to connect. If your computer is otherwise connecting to
the Internet the problem

may be with a firewall or anti-virus program blocking GMap Kit.", 64, "GMap
Kit Network Error"
ProcessWNRError = 0

Case 12009 'A request to WinHttpQueryOption or WinHttpSetOption
specified an invalid option

value.
LRet = MsgBox("Error with WinHTTP options. If you are using TLS for
secure connection[ see

program settings] try not using it.", 64, "GMap Kit Network Error")
ProcessWNRError = 0

Case 12037 'cert outdated.
LRet = MsgBox("Certificate is expired. This could be a security risk.
Do you want to continue?",

36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case 12038 'Returned when a certificate CN name does not match the
passed value (equivalent to

a CERT_E_CN_NO_MATCH error).
LRet = MsgBox("Security certificate name does not match. This could
be a security risk. Do you

want to continue?", 36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case 12170 'Indicates that a certificate has been revoked (equivalent
to CRYPT_E_REVOKED).
LRet = MsgBox("Certificate has been revoked. This could be a security
risk. Do you want to

continue?", 36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case 12157 'Indicates that an error occurred having to do with a secure
channel (equivalent to

error codes that begin with "SEC_E_" and "SEC_I_" listed in the "winerror.h"
header file).
LRet = MsgBox("Error with WinHTTP options. If you are using TLS for
secure connection[ see

program settings] and this error continues, try not using it.", 64, "GMap
Kit Network Error")
ProcessWNRError = 0

Case 12175 'One or more errors were found in the Secure Sockets Layer
(SSL) certificate sent by

the server. To determine what type of error was encountered, check for a

WINHTTP_CALLBACK_STATUS_SECURE_FAILURE notification in a status callback
function. For more

information, see WINHTTP_STATUS_CALLBACK.
LRet = MsgBox("Errors in certificate sent by server. This could be a
security risk. Do you want to

continue?", 36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case 12045 'Indicates that a certificate chain was processed, but
terminated in a root certificate

that is not trusted by the trust provider (equivalent to
CERT_E_UNTRUSTEDROOT).
LRet = MsgBox("Certificate sent by server is not trusted. This could
be a security risk. Do you

want to continue?", 36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case 12169 'Indicates that a certificate is invalid (equivalent to
errors such as CERT_E_ROLE,

CERT_E_PATHLENCONST, CERT_E_CRITICAL, CERT_E_PURPOSE, CERT_E_ISSUERCHAINING,

CERT_E_MALFORMED and CERT_E_CHAINING).
LRet = MsgBox("Certificate sent by server is invalid. This could be a
security risk. Do you want to

continue?", 36, "GMap Kit Network Error")
If LRet = 6 Then ProcessWNRError = 1 Else ProcessWNRError = 0

Case Else
ProcessWNRError = -1 'show basic error info and quit.
End Select

End Function


Public Function GetLowInt(LongIn As Long) As Integer
On Error Resume Next
If (LongIn And &HFFFF&) > &H7FFF Then
GetLowInt = (LongIn And &HFFFF&) - &H10000
Else
GetLowInt = LongIn And &HFFFF&
End If
End Function


'------------- gzip code:

Public Type zStream
next_in As Long
avail_in As Long
total_in As Long
next_out As Long
avail_out As Long
total_out As Long
MSG As Long
state As Long
zalloc As Long
zfree As Long
opaque As Long
data_type As Long
adler As Long
reserved As Long
End Type

Public Type GZHead ' 10 bytes
ID1 As Byte '31
ID2 As Byte '139
CM As Byte '8 compression method. (8 is only option!)
FLG As Byte ' flags.
MTime As Long ' modified date. set to 0 on write. ignore on read.
XFL As Byte '0
OS As Byte '0
End Type

Private Const Z_FINISH As Long = 4
Private Const Z_STREAM_END = 1


Private Declare Function inflateInit2 Lib "zlibw125.dll" Alias
"inflateInit2_" (strm As zStream, ByVal

windowBits As Long, ByVal ZLibVersion As String, ByVal zStream_size As Long)
As Long
Private Declare Function inflate Lib "zlibw125.dll" (vStream As zStream,
ByVal vflush As Long) As

Long
Private Declare Function inflateEnd Lib "zlibw125.dll" (vStream As zStream)
As Long

Public Function GUnzip2(AIn() As Byte, LErr As Long) As Byte()
Dim A2() As Byte
Dim LRet As Long, LenDData As Long, LenCData As Long
Dim ZS As zStream
On Error Resume Next
LenCData = UBound(AIn) + 1
CopyMemory LenDData, AIn(UBound(AIn) - 3), 4 '--get total size.
ReDim A2(LenDData - 1) As Byte
With ZS
.zalloc = 0
.zfree = 0
.opaque = 0
.avail_in = LenCData
.avail_out = LenDData
.next_in = VarPtr(AIn(0))
.next_out = VarPtr(A2(0))
End With
LRet = inflateInit2(ZS, 47, "1.2.5.0", Len(ZS))
If LRet <> 0 Then
LErr = LRet 'negative number errors.
Exit Function
End If
LRet = inflate(ZS, Z_FINISH)
If LRet = 1 Then LRet = 0 '-- 0 is OK. 1 is returned when the whole
thing has been

decompressed.
LErr = LRet
LRet = inflateEnd(ZS)
If (LErr <> 0) Then Exit Function
'-- make sure transfer of array is last call to avoid duplication of
array.
GUnzip2 = A2
End Function
GS
2017-04-27 01:26:09 UTC
Permalink
Wow! Lots to digest and certainly not as simple as UrlDownloadToFile. Perhaps a
wrapper is the way to go where I can use it in similar fashion
(sourceFile,targetFile args)!!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-27 03:28:40 UTC
Permalink
"GS" <***@v.invalid> wrote

| Wow! Lots to digest and certainly not as simple as UrlDownloadToFile.
Perhaps a
| wrapper is the way to go where I can use it in similar fashion
| (sourceFile,targetFile args)!!
|

Yes. It's easier than it looks. I just wanted to pad
it with all the luxuries, like gzip support and extensive
error handling. But the main advantage is that it handles
https transparently. And even without that, winsock
is a lot more work.

On the other hand, there's always the WB control, which
is pretty much UrlDownloadToFile. Navigate has flags to
avoid cache and history. But personally I find that kind
of hokey.

There's also a very simple method provided by the
userControl. Karl Peterson has a sample at his site.

http://vb.mvps.org/samples/NetGrab/

For some reason Filzip says it's not a valid ZIP, but
7-Zip opened it. Karl's code is very simple. Kind of
a hidden gem. But I don't think it does SSL/TLS,
and that's becoming something that people expect
these days.
GS
2017-04-28 05:11:39 UTC
Permalink
Post by Mayayana
Post by GS
Wow! Lots to digest and certainly not as simple as UrlDownloadToFile.
Perhaps a wrapper is the way to go where I can use it in similar fashion
(sourceFile,targetFile args)!!
Yes. It's easier than it looks. I just wanted to pad
it with all the luxuries, like gzip support and extensive
error handling. But the main advantage is that it handles
https transparently. And even without that, winsock
is a lot more work.
On the other hand, there's always the WB control, which
is pretty much UrlDownloadToFile. Navigate has flags to
avoid cache and history. But personally I find that kind
of hokey.
There's also a very simple method provided by the
userControl. Karl Peterson has a sample at his site.
http://vb.mvps.org/samples/NetGrab/
For some reason Filzip says it's not a valid ZIP, but
7-Zip opened it. Karl's code is very simple. Kind of
a hidden gem. But I don't think it does SSL/TLS,
and that's becoming something that people expect
these days.
Karl's UC is a great tool but I'm working with Excel VBA here and so I'm going
to plug through your code because nothing I've found is working properly (just
getting empty file)!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-28 13:28:26 UTC
Permalink
"GS" <***@v.invalid> wrote

| Karl's UC is a great tool but I'm working with Excel VBA here and so I'm
going
| to plug through your code because nothing I've found is working properly
(just
| getting empty file)!
|

I'm sorry that I don't have a clean UC to offer you.
I never wrote a straight winhttp UC. I use it to call
Google Maps server, and adapted it from a winsock
UC. (The winsock file-downloading UC is available on
my VB6 page, but it doesn't do https.)

The actual winhttp code is actually very minimal.
(At least it seems that way to me after using winsock.)

The rest of my code is mostly specifics for my program.
JSON parsing and such. (Google, like everyone else,
have gone bonkers for both XML and JSON. I half expect
that Microsoft, one of these days, will come out with a
programming language composed of nothing but curly
brackets, GUIDs and XML.)

If you look at the main function code you'll see that
it's mostly a lot of potential error handling. Comparing
it to the error info function, ProcessWNRError, will
explain the steps in the Select Case filter. In theory
you could cut out everything but the lines with the
WHR (winhttprequest) object and then just check to
see if your array is holding anything and return the server
response code (200, 404, etc).

I was writing freeware and wanted to be sure that if
maps didn't come through, the end user would at least
have as much info as possible to figure out whether it's
their connection, the Google server, an invalid request,
or whatever. Especially given the complications of https.
Part of the code is to provide the option to relax
certificate strictness if necessary. It's ridiculously common
for sites to let their certificates expire or to use their
somewhere.com cert for their swhere.com domain. If
that's not dealt with then either you have no security
or you fail to get files half the time. On the other hand,
if you don't care about https then you can skip all that
and just check the server header for error code. (200,
404, etc)

That's a nice aspect of winhttp. It's a convenient
compromise between the dummy functionality IE wrapper
of wininet and the closer control of winsock.
GetAllResponseHeaders returns the server response and
SetRequestHeader allows you to customize the server
conversation from your end. So you get most of the
control of winsock without the work.
GS
2017-04-28 19:22:30 UTC
Permalink
Thanks for the followup! It'll be a while before I get the time to sort through
and pull only what I need to read a text file of form results...

BTW:
I continued looking into using php for form processing to a text file AFTER I
left you a contact msg on your website. That's working very well now nd so my
focus is on download/read an online file. Here's what I'm using with
WinHttpRequest.5.1...

Set oWHR = CreateObject("WinHttp.WinHttpRequest.5.1")
oWHR.Open "GET", sSrcFile, False
' Use HTTPREQUEST_SETCREDENTIALS_FOR_PROXY if user and password
' is for proxy, not for download the file.
' objHTTP.SetCredentials "User", "Password",
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
oWHR.Send

If oWHR.Status = 200 Then
Dim oADO
Set oADO = CreateObject("ADODB.Stream")
With oADO
.Type = 2: .Open: .Write oWHR.ResponseBody: .SaveToFile sTgtFile: .Close
End With
End If

..which, so far, just creates an empty file. Can you see where something is
missing?
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-28 23:16:29 UTC
Permalink
"GS" <***@v.invalid> wrote

You're doing this in VBS? I thought you were using
VB. I've never done it in VBS. There are several parts
here I'm not sure about. I've never needed/used
SetCredentials. You didn't need to adjust the send
header at all? You didn't check the error and I don't
know if you're using https, so that leaves unanswered
questions.

I'm curious why you set the version of winhttp. I
guess it's fine, but won't that limit you if you run
from a machine that has, say, 5.2?

It appears you got a 200 response if you're writing
to disk. So maybe all the above doesn't matter. I'm
not really familiar with ADODB and you've scrunched it
all into a dubious one-liner, so I also don't know how
to troubleshoot that. You realize the return is a byte
array? I don't know what Type 2 is. Hopefully that's
binary.


|
| Set oWHR = CreateObject("WinHttp.WinHttpRequest.5.1")
| oWHR.Open "GET", sSrcFile, False
| ' Use HTTPREQUEST_SETCREDENTIALS_FOR_PROXY if user and password
| ' is for proxy, not for download the file.
| ' objHTTP.SetCredentials "User", "Password",
| HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
| oWHR.Send
|
| If oWHR.Status = 200 Then
| Dim oADO
| Set oADO = CreateObject("ADODB.Stream")
| With oADO
| .Type = 2: .Open: .Write oWHR.ResponseBody: .SaveToFile sTgtFile:
.Close
| End With
| End If
|
| ..which, so far, just creates an empty file. Can you see where something
is
| missing?
|
| --
| Garry
|
| Free usenet access at http://www.eternal-september.org
| Classic VB Users Regroup!
| comp.lang.basic.visual.misc
| microsoft.public.vb.general.discussion
GS
2017-04-29 02:08:27 UTC
Permalink
This is VB[A} code, not VBS!

Type 2 is text because that's what the download file is, not a binary file.
(Though I'll change it to Type 1 and see if that makes a difference.

ADODB is what the samples I found online are using to write .ResponseBody to
the local file...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 02:11:53 UTC
Permalink
Post by GS
This is VB[A} code, not VBS!
Type 2 is text because that's what the download file is, not a binary file.
(Though I'll change it to Type 1 and see if that makes a difference.
ADODB is what the samples I found online are using to write .ResponseBody to
the local file...
Aha.., Type 1 works! Thanks for catching that...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 02:17:32 UTC
Permalink
Post by GS
Aha.., Type 1 works! Thanks for catching that...
Wow! This method is orders of magnitude faster; -UrlDownloadToFile took a few
seconds (didn't actually time it, just counted in my head) and WinHttpRequest
was done in a blink!

I removed the version spec...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 02:21:53 UTC
Permalink
Post by GS
This is VB[A} code, not VBS!
Type 2 is text because that's what the download file is, not a binary file.
(Though I'll change it to Type 1 and see if that makes a difference.
ADODB is what the samples I found online are using to write .ResponseBody to
the local file...
Oops.., spoke too soon. Now I'm getting an empty file again.
Back to the drawing board...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-29 02:37:55 UTC
Permalink
"GS" <***@v.invalid> wrote

| Oops.., spoke too soon. Now I'm getting an empty file again.
| Back to the drawing board...

It's always a byte array, but you can also try
ResponseText. I haven't bothered. I just handle
a byte array because I get different file types.

VBA can't do just a basic write, like this?

FF = FreeFile()
Open sPath For Binary As #FF
Put #FF, , AFile
Close #FF

I don't see why you'd need to bring in something
like adodb. My understanding is that's something
mainly for scripting. Another dependency.
GS
2017-04-29 04:01:30 UTC
Permalink
Post by Mayayana
Post by GS
Oops.., spoke too soon. Now I'm getting an empty file again.
Back to the drawing board...
It's always a byte array, but you can also try
ResponseText. I haven't bothered. I just handle
a byte array because I get different file types.
Hmm! Didn't see anything exampling ResponseText...
Post by Mayayana
VBA can't do just a basic write, like this?
Not sure because it's downloading a plain text file, not a binary file. Are you
saying it becomes binary during the process?
Post by Mayayana
FF = FreeFile()
Open sPath For Binary As #FF
Put #FF, , AFile
Close #FF
I don't see why you'd need to bring in something
like adodb. My understanding is that's something
mainly for scripting. Another dependency.
Yeah, I was wondering about that myself but aborted 'spending' time on it since
the file created was/is empty.

Anyway, since I found the API to clear the cache I'm going to stick with
UrlDownloadToFile unless someone shows me 'drop-in' code to download text files
via WinHttpRequest...<g>
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 05:19:09 UTC
Permalink
Post by GS
Post by Mayayana
Post by GS
Oops.., spoke too soon. Now I'm getting an empty file again.
Back to the drawing board...
It's always a byte array, but you can also try
ResponseText. I haven't bothered. I just handle
a byte array because I get different file types.
Hmm! Didn't see anything exampling ResponseText...
Post by Mayayana
VBA can't do just a basic write, like this?
Not sure because it's downloading a plain text file, not a binary file. Are
you saying it becomes binary during the process?
Post by Mayayana
FF = FreeFile()
Open sPath For Binary As #FF
Put #FF, , AFile
Close #FF
I don't see why you'd need to bring in something
like adodb. My understanding is that's something
mainly for scripting. Another dependency.
Yeah, I was wondering about that myself but aborted 'spending' time on it
since the file created was/is empty.
Anyway, since I found the API to clear the cache I'm going to stick with
UrlDownloadToFile unless someone shows me 'drop-in' code to download text
files via WinHttpRequest...<g>
Found a function (2 actually) that return the file contents using
WinHttpRequest and passing URL,FullFilename as args. Not as lengthy<g> as your
sample, but serves as a drop-in wrapper that gets the job done. I just write
the return to file using normal VB file i/o!

Thanks again for your most appreciated efforts in helping me get this worked
out!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 05:46:14 UTC
Permalink
Post by Mayayana
Post by GS
Oops.., spoke too soon. Now I'm getting an empty file again.
Back to the drawing board...
It's always a byte array, but you can also try
ResponseText. I haven't bothered. I just handle
a byte array because I get different file types.
VBA can't do just a basic write, like this?
FF = FreeFile()
Open sPath For Binary As #FF
Put #FF, , AFile
Close #FF
I don't see why you'd need to bring in something
like adodb. My understanding is that's something
mainly for scripting. Another dependency.
Ok, I was able to tweak things out so the WinHttpRequest code is...

<snip>
Set oWHR = CreateObject("WinHttp.WinHttpRequest.5.1")
oWHR.Open "POST", sSrcFile, False
oWHR.Send

If oWHR.Status = 200 Then
WriteTextFile oWHR.ResponseText, sTgtFile
End If
</snip>

..which obviates needing the wrapper function. Note that including the version
supports features not included in earlier versions. Note also that I change the
method arg to "POST" instead of "GET" just to see what happens; -both work but
I'll revert to using "GET" anyway.

Now I can have it both ways and not have files left in the cache!<bg>
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 16:36:12 UTC
Permalink
Tweaking further.., since all I need is to dump .ResponseText directly into my
array for processing the data. This means I can dispense with writing to file
just to read back into my array. IMO, that's a lot cleaner method than
UrlDownloadToFile...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-29 23:59:40 UTC
Permalink
"GS" <***@v.invalid> wrote

| Tweaking further.., since all I need is to dump .ResponseText directly
into my
| array for processing the data. This means I can dispense with writing to
file
| just to read back into my array. IMO, that's a lot cleaner method than
| UrlDownloadToFile...
|

It sounds like you're all set. Winhttp allows for lots
of functionality and does it easily, but since you
don't need any of that, there's no reason not to just
do it in a few lines. It's very easy and avoids all that
tacky, privacy infringing IE wrapper stuff.

It's surprising how many people don't know about
the wininet/IE tie-in. I got into a debate about it once
with Deanna in the VB group. From all indications she's
a more experienced programmer than I'll ever be, yet
she insisted that IE cache is windows cache, IE cookies
are Windows cookies and wininet is the Windows
Internet library. She works in low level C++ yet couldn't
see using anything but an IE wrapper to download files.
It was bizarre. No one would think it normal to call
UrlDownloadTofile and end up setting Firefox cookies.
But commercial programmers in "Windows shops" have
been trained to conflate IE and Internet through years
of "thought leadership" from Microsoft.
GS
2017-04-30 00:18:27 UTC
Permalink
Post by Mayayana
Tweaking further.., since all I need is to dump .ResponseText directly into
my array for processing the data. This means I can dispense with writing to
file just to read back into my array. IMO, that's a lot cleaner method than
UrlDownloadToFile...
It sounds like you're all set. Winhttp allows for lots
of functionality and does it easily, but since you
don't need any of that, there's no reason not to just
do it in a few lines. It's very easy and avoids all that
tacky, privacy infringing IE wrapper stuff.
It's surprising how many people don't know about
the wininet/IE tie-in. I got into a debate about it once
with Deanna in the VB group. From all indications she's
a more experienced programmer than I'll ever be, yet
she insisted that IE cache is windows cache, IE cookies
are Windows cookies and wininet is the Windows
Internet library. She works in low level C++ yet couldn't
see using anything but an IE wrapper to download files.
It was bizarre. No one would think it normal to call
UrlDownloadTofile and end up setting Firefox cookies.
But commercial programmers in "Windows shops" have
been trained to conflate IE and Internet through years
of "thought leadership" from Microsoft.
Yeah, I recall following that debate! Don't know much about her but I get the
impression she's 'top level' in programming. Relatively speaking, since my
background is primarily Excel VBA, I consider myself a 'hack novice' VB
programmer. I don't have a clue where I'd be today if it wasn't for all the
help I've received in these NGs!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
GS
2017-04-29 03:50:57 UTC
Permalink
Meanwhile, this API function solves the issue of update calls reading from
cache...

DeleteUrlCacheEntry()
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-28 23:29:31 UTC
Permalink
"GS" <***@v.invalid> wrote
| BTW:
| I continued looking into using php for form processing to a text file
AFTER I
| left you a contact msg on your website. That's working very well now nd so
my
| focus is on download/read an online file. Here's what I'm using with
| WinHttpRequest.5.1...
|

Today you sent a message? I didn't get it.
Did you send it from non-freebie webmail?
Anything like gmail, yahoo, hotmail is auto-deleted.
GS
2017-04-29 02:04:34 UTC
Permalink
Post by Mayayana
I continued looking into using php for form processing to a text file AFTER
I left you a contact msg on your website. That's working very well now nd so
my focus is on download/read an online file. Here's what I'm using with
WinHttpRequest.5.1...
Today you sent a message? I didn't get it.
Did you send it from non-freebie webmail?
Anything like gmail, yahoo, hotmail is auto-deleted.
Not today. It was last week via the contact form on your website!
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Mayayana
2017-04-29 02:25:39 UTC
Permalink
"GS" <***@v.invalid> wrote

| Not today. It was last week via the contact form on your website!
|
Hmm. I do tend to get one or two spam per day
from companies that want to sell me website help.
They typically have subjects like Help or Info. I delete
those. I'm sorry if I missed yours. I just tested it and
it's working fine. So accidentally deleting your email
is the only thing I can think of.

It sounds like you don't still need PHP help but I
would say that I'm no expert. I figure out what I
need to. Mostly I've just needed to do includes in
order to serve different pages to IE vs other
browsers. Other than that I've never needed much
in terms of server-side functionality.
GS
2017-04-29 02:31:41 UTC
Permalink
Post by Mayayana
Post by GS
Not today. It was last week via the contact form on your website!
Hmm. I do tend to get one or two spam per day
from companies that want to sell me website help.
They typically have subjects like Help or Info. I delete
those. I'm sorry if I missed yours. I just tested it and
it's working fine. So accidentally deleting your email
is the only thing I can think of.
It sounds like you don't still need PHP help but I
would say that I'm no expert. I figure out what I
need to. Mostly I've just needed to do includes in
order to serve different pages to IE vs other
browsers. Other than that I've never needed much
in terms of server-side functionality.
PHP is new to me but wasn't hard to figure out after a visit to the W3School
online tutorials. I've only ever processed form results into emails via
formmail.pl...
--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
Ulrich Möller
2017-04-18 17:20:17 UTC
Permalink
Hi Rudy,
Post by R.Wieser
Bonus question (for when the first is impossible): How do I convert a string
into one I can actually write to a file WITHOUT having to go thru it
byte-by-byte (copy the aceptable ones into a new string and write that one)
? I've already tried CStr and Trim, but neither are helpfull.:-\
here are some examples to accomplish this:
http://www.motobit.com/tips/detpg_binarytostring/

Maybe you can use responeXML instead of responseText of the XMLHTTP
object in your project.
See https://msdn.microsoft.com/en-us/library/ms762275(v=vs.85).aspx
<https://msdn.microsoft.com/en-us/library/ms762275%28v=vs.85%29.aspx>(section
remarks) for some hints.

Another interesting object is the ado.stream object. I sometimes uses it
for decoding charsets from utf-8 to unicode.

Ulrich
R.Wieser
2017-04-18 17:58:48 UTC
Permalink
Ulrich,
Thanks for the examples, but those only work when you can load a file
containing multi-byte chars in as plain ASCII (and thereby getting access to
every byte of a multi-byte sequence seperatily). In my case thats not
applicable (I already have the string, and can't change its ASCII- or
Unicode-ness).
Post by Ulrich Möller
Maybe you can use responeXML instead of responseText of the
XMLHTTP object in your project.
Sorry, nope. The object throws an error when I try to use that method.
Post by Ulrich Möller
Another interesting object is the ado.stream object. I sometimes
uses it for decoding charsets from utf-8 to unicode.
I need to go the other way*, but it could not hurt to take a look it.

*actually, I only need to be able to negate VBScripts everything-to-unicode
translation, and get the (presumed to be MultiByte) origional back and than
into the file.

Regards,
Rudy Wieser
Post by Ulrich Möller
Hi Rudy,
Post by R.Wieser
Bonus question (for when the first is impossible): How do I convert a string
into one I can actually write to a file WITHOUT having to go thru it
byte-by-byte (copy the aceptable ones into a new string and write that one)
? I've already tried CStr and Trim, but neither are helpfull.:-\
http://www.motobit.com/tips/detpg_binarytostring/
Maybe you can use responeXML instead of responseText of the XMLHTTP
object in your project.
See https://msdn.microsoft.com/en-us/library/ms762275(v=vs.85).aspx
<https://msdn.microsoft.com/en-us/library/ms762275%28v=vs.85%29.aspx>(sectio
n
Post by Ulrich Möller
remarks) for some hints.
Another interesting object is the ado.stream object. I sometimes uses it
for decoding charsets from utf-8 to unicode.
Ulrich
Ulrich Möller
2017-04-19 12:59:38 UTC
Permalink
Hi Rudy
Post by R.Wieser
Post by Ulrich Möller
Another interesting object is the ado.stream object. I sometimes
uses it for decoding charsets from utf-8 to unicode.
I need to go the other way*, but it could not hurt to take a look it.
*actually, I only need to be able to negate VBScripts everything-to-unicode
translation, and get the (presumed to be MultiByte) origional back and than
into the file.
Normally vbscript handles a string as pure binary data. Assignments to
other vars are handled transparently. The problem occurs, when you try
to modify the string.

So to write this string transparently into a file simple use the
ado.stream object. Instantiate the object, set the type to binary and
write the string into the stream. Then you will be able to write the
stream content to a file with the ado.stream object.

Btw, if you want to pick some bytes from the string, you can use the
MidB function to extract a data byte from a string.

Ulrich
R.Wieser
2017-04-19 14:46:08 UTC
Permalink
Ulrich,
Post by Ulrich Möller
Normally vbscript handles a string as pure binary data.
Thats not what I know about VBScript (or the environment it runs in). Try
to find a Variant type which will be able to hold a binary and/or ASCII
string. I think you will be hard-pressed.
Post by Ulrich Möller
So to write this string transparently into a file simple use the
ado.stream object.
Multiple problems "ado.stream" seems to be a rather elusive google search
term

The line "set oStream = new stream" throws an error: object not found (did I
already mention the 'puter is oldish ?)

But if its so simple, whats than wrong with using the
Scripting.FileSystemObject objects CreateTextFile ?
Post by Ulrich Möller
set the type to binary and write the string into the stream.
How would that be different than writing the string to a file of the type
ASCII ?
Post by Ulrich Möller
Btw, if you want to pick some bytes from the string, you can use
the MidB function to extract a data byte from a string.
You obviously haven't read shit about the stuff I've alread posted (in
response to Mayayana). I have absolutily *zero* wish to got to thru the
whole shebang again. Go pester someone else please.

Regards,
Rudy Wieser
Post by Ulrich Möller
Hi Rudy
Post by R.Wieser
Post by Ulrich Möller
Another interesting object is the ado.stream object. I sometimes
uses it for decoding charsets from utf-8 to unicode.
I need to go the other way*, but it could not hurt to take a look it.
*actually, I only need to be able to negate VBScripts
everything-to-unicode
Post by Ulrich Möller
Post by R.Wieser
translation, and get the (presumed to be MultiByte) origional back and than
into the file.
Normally vbscript handles a string as pure binary data. Assignments to
other vars are handled transparently. The problem occurs, when you try
to modify the string.
So to write this string transparently into a file simple use the
ado.stream object. Instantiate the object, set the type to binary and
write the string into the stream. Then you will be able to write the
stream content to a file with the ado.stream object.
Btw, if you want to pick some bytes from the string, you can use the
MidB function to extract a data byte from a string.
Ulrich
Loading...