Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #12465
| Newsgroups | microsoft.public.scripting.vbscript |
|---|---|
| Date | 2022-10-08 12:19 -0700 |
| References | <661f1763-6f55-44ce-8360-ca5f9f99aeb5n@googlegroups.com> |
| Message-ID | <69906fc6-5fec-4d80-8fea-872ed901204bn@googlegroups.com> (permalink) |
| Subject | Re: Using CHRW to speed up writing binary files |
| From | Antoni Gual Via <antonigualvia@gmail.com> |
I have found the solution. To write data to a binary file two bytes at a time is possible, but the increase ins speed is just marginal (in my old laptop). I forgot you can add a "&" suffix to a number to declare it as a long. Here is the code:
fn=CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)& "\testwchr.bmp"
Function long2wstr( x) 'falta muy poco!!!
Dim k1,k2,x1
k1=((x And &h7fff) Or (&H8000& And ((X And &h8000&)<>0)))
k2=((X And &h7fffffff&) \ &h10000&) Or (&H8000& And ((X And &h80000000&) <>0 ))
long2wstr=chrw(k1) & chrw(k2)
End Function
Function wstr2long(s)
x1=AscW(mid(s,1,1))
xx1=x1-(65536 *(x1<0))
x2=AscW(mid(s,2,1))
wstr2long=x2*65536+xx1
End Function
Function rndlong() rndlong=CLng(4294967296* rnd()-2147483648+256*rnd) :End Function
Dim a(1000)
With CreateObject("ADODB.Stream")
.Charset = "UTF-16LE" 'o "UTF16-BE"
.Type = 2' adTypeText
.open
Randomize timer
For I=0 To 1000
a(i)=rndlong
.writetext long2wstr(a(i))
Next
.savetofile fn,2
.close
'now read the file to see if ADODB has changed anything
.open
.loadfromfile fn
.position=2 'skip bom
cnt=0
For I=0 To 1000
j= wstr2long(.readtext (2))
If j<>a(i) Then WScript.Echo a(i),j:cnt=cnt+1
Next
WScript.Echo cnt 'should print 0
.close
End With
Back to microsoft.public.scripting.vbscript | Previous | Next — Previous in thread | Next in thread | Find similar
Using CHRW to speed up writing binary files Antoni Gual Via <antonigualvia@gmail.com> - 2022-10-08 09:45 -0700
Re: Using CHRW to speed up writing binary files Antoni Gual Via <antonigualvia@gmail.com> - 2022-10-08 12:19 -0700
Re: Using CHRW to speed up writing binary files JJ <jj4public@outlook.com> - 2022-10-09 20:26 +0700
Re: Using CHRW to speed up writing binary files "Mayayana" <mayayana@invalid.nospam> - 2022-10-10 08:06 -0400
Re: Using CHRW to speed up writing binary files Antoni Gual Via <antonigualvia@gmail.com> - 2022-10-10 08:23 -0700
Re: Using CHRW to speed up writing binary files "Mayayana" <mayayana@invalid.nospam> - 2022-10-10 17:40 -0400
csiph-web