You "open" the file with LoadFromFile; Open opens the stream. Yes, you
can use Open() to read a local file, but I prefer the self-documenting
nature of LoadFromFile().
[...]
> Const adModeShareDenyWrite = 8 'has to be explicitly declared
> Const adOpenStreamAsync = 1 'in WSH
Both of which are entirely unnecessary in this case
[...]
> Function OpenStream(ByVal strFilePath)
> Dim oADOStream
> Set oADOStream = CreateObject("ADODB.Stream")
> 'Set OpenStream = oADOStream.open(strFilePath, _
> ' adModeShareDenyWrite, adOpenStreamAsync)
According to the ADO API Reference, if Source (the first element to
Open()) is specifying a URL, it should be in the form
"URL=scheme://server/folder". For a local file, it should therefore be
"URL=file:///c:/io.sys".
> Set OpenStream = oADOStream.LoadFromFile(strFilePath)
> End Function
>
>
> There Error with 'LoadFromFile' is: 'Operation not allowed
> on closed object' (Translated from german error-msg)
Quite correctly; you can't load a file into a stream that you haven't
opened.
> There Error with 'Open' is: 'Arguments are of false type, are out
> valid range or not compatible with each other',
> even if I only use the first parameter (Source), same error.
> I also get this error when i pass the source-arg in
> file-protocol-format: "file:///C:/io.sys".
See above - you should be prefixing the source with URL=.
> btw its not a fundamental problem, "adodb.stream" works
> with wsh. e.g. I use it without problems for Writing
> binary data to file.
>
> Can anybody give me a hint how to use open or loadfromfile
The first thing you seem to be confused about is that LoadFromFile()
_doesn't_ return anything. If an error occured, the call failed; if not,
it succeeded. You're also trying to load a binary file as text, which
isn't really a good idea.
For example:
Const adTypeBinary = 1
Set objStream = CreateObject( "ADODB.Stream" )
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile( "c:\io.sys" )
populates objStream with the contents of c:\io.sys.
You would then use
varTemp = objStream.Read()
to read from the stream.
hth
Adam
--
I'm glad I was not born before tea.
-- Sidney Smith (1771-1845)