Writing to a file

Discussion in 'ASP General' started by Andrew Chalk, Aug 5, 2003.

  1. Andrew Chalk

    Andrew Chalk Guest

    Can I write to a binary file from a VB script?

    I get a syntax error:

    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /Web2_Local/custquery.asp, line 180, column 21
    Open "DOWNLOAD.FIL" For Binary Access Write As #1


    Many thanks.
    Andrew Chalk, Aug 5, 2003
    #1
    1. Advertising

  2. Andrew Chalk

    Ray at Guest

    You're trying to use Visual Basic code in your ASP page. Use VB Script.
    There is no "open file for input as #1" or anything like that in VBS like in
    VB. Download the Windows Scripting Host documentation and read up on the
    File Scripting Object.

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Andrew Chalk" <> wrote in message
    news:...
    > Can I write to a binary file from a VB script?
    >
    > I get a syntax error:
    >
    > Error Type:
    > Microsoft VBScript compilation (0x800A0401)
    > Expected end of statement
    > /Web2_Local/custquery.asp, line 180, column 21
    > Open "DOWNLOAD.FIL" For Binary Access Write As #1
    >
    >
    > Many thanks.
    >
    >
    Ray at, Aug 5, 2003
    #2
    1. Advertising

  3. Andrew Chalk

    Ray at Guest

    About the FSO:
    "Although it does not yet support the creation or manipulation of binary
    files, future support of binary files is planned."

    What are you trying to do?

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Andrew Chalk" <> wrote in message
    news:...
    > Is that different from the "File System Object"? That only hanldes text
    > files. I need to write a binary file.
    >
    > Regards
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:...
    > > You're trying to use Visual Basic code in your ASP page. Use VB Script.
    > > There is no "open file for input as #1" or anything like that in VBS

    like
    > in
    > > VB. Download the Windows Scripting Host documentation and read up on

    the
    > > File Scripting Object.
    > >
    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > >
    > > Ray at home
    > >
    > > --
    > > Will trade ASP help for SQL Server help
    > >
    > >
    > > "Andrew
    Ray at, Aug 5, 2003
    #3
  4. Andrew Chalk

    Andrew Chalk Guest

    When the user click a specific button, I perform a database lookup and then
    format the returned data into a binary file. I write that to disk and pop up
    the "file download" dialog so that the user can d/l the file.

    I am assuming that because the file I create can contain arbitrary data, it
    should be what VB calls a "binary" file. Although I don't know. A so-called
    "text file" may work.

    Regards.

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > About the FSO:
    > "Although it does not yet support the creation or manipulation of binary
    > files, future support of binary files is planned."
    >
    > What are you trying to do?
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Andrew Chalk" <> wrote in message
    > news:...
    > > Is that different from the "File System Object"? That only hanldes text
    > > files. I need to write a binary file.
    > >
    > > Regards
    > >
    > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > > news:...
    > > > You're trying to use Visual Basic code in your ASP page. Use VB

    Script.
    > > > There is no "open file for input as #1" or anything like that in VBS

    > like
    > > in
    > > > VB. Download the Windows Scripting Host documentation and read up on

    > the
    > > > File Scripting Object.
    > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > >
    > > > Ray at home
    > > >
    > > > --
    > > > Will trade ASP help for SQL Server help
    > > >
    > > >
    > > > "Andrew

    >
    >
    Andrew Chalk, Aug 5, 2003
    #4
  5. Andrew Chalk

    Ray at Guest

    Okay, well, you can in fact use the FSO to write binary files. There are
    file upload scripts that use nothing but vbscript to process and write
    binary files to a server. Here is one example.
    http://www.aspzone.com/Entries/88f007f3d7c94567ab2d8b17e120520d.aspx
    This isn't what you're trying to do, but study this and you'll see how he
    creates binary "text" files.

    Also, for returning binary data to the user for download, here's a nice tip.
    http://www.aspfaq.com/show.asp?id=2161

    Ray at work




    "Andrew Chalk" <> wrote in message
    news:%...
    > When the user click a specific button, I perform a database lookup and

    then
    > format the returned data into a binary file. I write that to disk and pop

    up
    > the "file download" dialog so that the user can d/l the file.
    >
    > I am assuming that because the file I create can contain arbitrary data,

    it
    > should be what VB calls a "binary" file. Although I don't know. A

    so-called
    > "text file" may work.
    >
    > Regards.
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:%...
    > > About the FSO:
    > > "Although it does not yet support the creation or manipulation of binary
    > > files, future support of binary files is planned."
    > >
    > > What are you trying to do?
    > >
    > > Ray at home
    > >
    > > --
    > > Will trade ASP help for SQL Server help
    > >
    > >
    > > "Andrew Chalk" <> wrote in message
    > > news:...
    > > > Is that different from the "File System Object"? That only hanldes

    text
    > > > files. I need to write a binary file.
    > > >
    > > > Regards
    > > >
    > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    message
    > > > news:...
    > > > > You're trying to use Visual Basic code in your ASP page. Use VB

    > Script.
    > > > > There is no "open file for input as #1" or anything like that in VBS

    > > like
    > > > in
    > > > > VB. Download the Windows Scripting Host documentation and read up

    on
    > > the
    > > > > File Scripting Object.
    > > > >
    > > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > > >
    > > > > Ray at home
    > > > >
    > > > > --
    > > > > Will trade ASP help for SQL Server help
    > > > >
    > > > >
    > > > > "Andrew

    > >
    > >

    >
    >
    Ray at, Aug 5, 2003
    #5
  6. Andrew Chalk

    Tom B Guest

    Is the actual data in the database? If so you can use ado to stream it from
    the database to the user.
    Is the filename in the database? If so you can just link to the file, or use
    FSO, to copy the file to a temporary location.

    "Andrew Chalk" <> wrote in message
    news:%...
    > When the user click a specific button, I perform a database lookup and

    then
    > format the returned data into a binary file. I write that to disk and pop

    up
    > the "file download" dialog so that the user can d/l the file.
    >
    > I am assuming that because the file I create can contain arbitrary data,

    it
    > should be what VB calls a "binary" file. Although I don't know. A

    so-called
    > "text file" may work.
    >
    > Regards.
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:%...
    > > About the FSO:
    > > "Although it does not yet support the creation or manipulation of binary
    > > files, future support of binary files is planned."
    > >
    > > What are you trying to do?
    > >
    > > Ray at home
    > >
    > > --
    > > Will trade ASP help for SQL Server help
    > >
    > >
    > > "Andrew Chalk" <> wrote in message
    > > news:...
    > > > Is that different from the "File System Object"? That only hanldes

    text
    > > > files. I need to write a binary file.
    > > >
    > > > Regards
    > > >
    > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    message
    > > > news:...
    > > > > You're trying to use Visual Basic code in your ASP page. Use VB

    > Script.
    > > > > There is no "open file for input as #1" or anything like that in VBS

    > > like
    > > > in
    > > > > VB. Download the Windows Scripting Host documentation and read up

    on
    > > the
    > > > > File Scripting Object.
    > > > >
    > > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > > >
    > > > > Ray at home
    > > > >
    > > > > --
    > > > > Will trade ASP help for SQL Server help
    > > > >
    > > > >
    > > > > "Andrew

    > >
    > >

    >
    >
    Tom B, Aug 5, 2003
    #6
  7. Andrew Chalk

    Andrew Chalk Guest

    Good points Tom. In this case actual raw data is in the database. However,
    the file I write contains that data transformed to comply with an external
    specification. Therefore, I can't stream it.

    Regards.
    "Tom B" <> wrote in message
    news:...
    > Is the actual data in the database? If so you can use ado to stream it

    from
    > the database to the user.
    > Is the filename in the database? If so you can just link to the file, or

    use
    > FSO, to copy the file to a temporary location.
    >
    > "Andrew Chalk" <> wrote in message
    > news:%...
    > > When the user click a specific button, I perform a database lookup and

    > then
    > > format the returned data into a binary file. I write that to disk and

    pop
    > up
    > > the "file download" dialog so that the user can d/l the file.
    > >
    > > I am assuming that because the file I create can contain arbitrary data,

    > it
    > > should be what VB calls a "binary" file. Although I don't know. A

    > so-called
    > > "text file" may work.
    > >
    > > Regards.
    > >
    > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > > news:%...
    > > > About the FSO:
    > > > "Although it does not yet support the creation or manipulation of

    binary
    > > > files, future support of binary files is planned."
    > > >
    > > > What are you trying to do?
    > > >
    > > > Ray at home
    > > >
    > > > --
    > > > Will trade ASP help for SQL Server help
    > > >
    > > >
    > > > "Andrew Chalk" <> wrote in message
    > > > news:...
    > > > > Is that different from the "File System Object"? That only hanldes

    > text
    > > > > files. I need to write a binary file.
    > > > >
    > > > > Regards
    > > > >
    > > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    > message
    > > > > news:...
    > > > > > You're trying to use Visual Basic code in your ASP page. Use VB

    > > Script.
    > > > > > There is no "open file for input as #1" or anything like that in

    VBS
    > > > like
    > > > > in
    > > > > > VB. Download the Windows Scripting Host documentation and read up

    > on
    > > > the
    > > > > > File Scripting Object.
    > > > > >
    > > > > >
    > > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > > > >
    > > > > > Ray at home
    > > > > >
    > > > > > --
    > > > > > Will trade ASP help for SQL Server help
    > > > > >
    > > > > >
    > > > > > "Andrew
    > > >
    > > >

    > >
    > >

    >
    >
    Andrew Chalk, Aug 5, 2003
    #7
  8. Andrew Chalk

    Andrew Chalk Guest

    That link:

    > http://www.aspfaq.com/show.asp?id=2161


    is very interesting. Works like a champ -- except that it prefaces the
    binary data with 3.5k of header bytes -- any idea why? I'm still looking
    through the docs. on this.

    Regards,

    Andrew

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > Okay, well, you can in fact use the FSO to write binary files. There are
    > file upload scripts that use nothing but vbscript to process and write
    > binary files to a server. Here is one example.
    > http://www.aspzone.com/Entries/88f007f3d7c94567ab2d8b17e120520d.aspx
    > This isn't what you're trying to do, but study this and you'll see how he
    > creates binary "text" files.
    >
    > Also, for returning binary data to the user for download, here's a nice

    tip.
    > http://www.aspfaq.com/show.asp?id=2161
    >
    > Ray at work
    >
    >
    >
    >
    > "Andrew Chalk" <> wrote in message
    > news:%...
    > > When the user click a specific button, I perform a database lookup and

    > then
    > > format the returned data into a binary file. I write that to disk and

    pop
    > up
    > > the "file download" dialog so that the user can d/l the file.
    > >
    > > I am assuming that because the file I create can contain arbitrary data,

    > it
    > > should be what VB calls a "binary" file. Although I don't know. A

    > so-called
    > > "text file" may work.
    > >
    > > Regards.
    > >
    > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > > news:%...
    > > > About the FSO:
    > > > "Although it does not yet support the creation or manipulation of

    binary
    > > > files, future support of binary files is planned."
    > > >
    > > > What are you trying to do?
    > > >
    > > > Ray at home
    > > >
    > > > --
    > > > Will trade ASP help for SQL Server help
    > > >
    > > >
    > > > "Andrew Chalk" <> wrote in message
    > > > news:...
    > > > > Is that different from the "File System Object"? That only hanldes

    > text
    > > > > files. I need to write a binary file.
    > > > >
    > > > > Regards
    > > > >
    > > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    > message
    > > > > news:...
    > > > > > You're trying to use Visual Basic code in your ASP page. Use VB

    > > Script.
    > > > > > There is no "open file for input as #1" or anything like that in

    VBS
    > > > like
    > > > > in
    > > > > > VB. Download the Windows Scripting Host documentation and read up

    > on
    > > > the
    > > > > > File Scripting Object.
    > > > > >
    > > > > >
    > > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > > > >
    > > > > > Ray at home
    > > > > >
    > > > > > --
    > > > > > Will trade ASP help for SQL Server help
    > > > > >
    > > > > >
    > > > > > "Andrew
    > > >
    > > >

    > >
    > >

    >
    >
    Andrew Chalk, Aug 5, 2003
    #8
  9. Andrew Chalk

    Andrew Chalk Guest

    Response.Clear removes most of the extraneous bytes -- but still leaves

    <!--METADATA TYPE="ASP_DEBUG_INFO"
    -->

    at the beginning.

    "Andrew Chalk" <> wrote in message
    news:%23Xkz$...
    > That link:
    >
    > > http://www.aspfaq.com/show.asp?id=2161

    >
    > is very interesting. Works like a champ -- except that it prefaces the
    > binary data with 3.5k of header bytes -- any idea why? I'm still looking
    > through the docs. on this.
    >
    > Regards,
    >
    > Andrew
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:%...
    > > Okay, well, you can in fact use the FSO to write binary files. There

    are
    > > file upload scripts that use nothing but vbscript to process and write
    > > binary files to a server. Here is one example.
    > > http://www.aspzone.com/Entries/88f007f3d7c94567ab2d8b17e120520d.aspx
    > > This isn't what you're trying to do, but study this and you'll see how

    he
    > > creates binary "text" files.
    > >
    > > Also, for returning binary data to the user for download, here's a nice

    > tip.
    > > http://www.aspfaq.com/show.asp?id=2161
    > >
    > > Ray at work
    > >
    > >
    > >
    > >
    > > "Andrew Chalk" <> wrote in message
    > > news:%...
    > > > When the user click a specific button, I perform a database lookup and

    > > then
    > > > format the returned data into a binary file. I write that to disk and

    > pop
    > > up
    > > > the "file download" dialog so that the user can d/l the file.
    > > >
    > > > I am assuming that because the file I create can contain arbitrary

    data,
    > > it
    > > > should be what VB calls a "binary" file. Although I don't know. A

    > > so-called
    > > > "text file" may work.
    > > >
    > > > Regards.
    > > >
    > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    message
    > > > news:%...
    > > > > About the FSO:
    > > > > "Although it does not yet support the creation or manipulation of

    > binary
    > > > > files, future support of binary files is planned."
    > > > >
    > > > > What are you trying to do?
    > > > >
    > > > > Ray at home
    > > > >
    > > > > --
    > > > > Will trade ASP help for SQL Server help
    > > > >
    > > > >
    > > > > "Andrew Chalk" <> wrote in message
    > > > > news:...
    > > > > > Is that different from the "File System Object"? That only hanldes

    > > text
    > > > > > files. I need to write a binary file.
    > > > > >
    > > > > > Regards
    > > > > >
    > > > > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in

    > > message
    > > > > > news:...
    > > > > > > You're trying to use Visual Basic code in your ASP page. Use VB
    > > > Script.
    > > > > > > There is no "open file for input as #1" or anything like that in

    > VBS
    > > > > like
    > > > > > in
    > > > > > > VB. Download the Windows Scripting Host documentation and read

    up
    > > on
    > > > > the
    > > > > > > File Scripting Object.
    > > > > > >
    > > > > > >
    > > > > >
    > > > >
    > > >

    > >

    >

    http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
    > > > > > >
    > > > > > > Ray at home
    > > > > > >
    > > > > > > --
    > > > > > > Will trade ASP help for SQL Server help
    > > > > > >
    > > > > > >
    > > > > > > "Andrew
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Andrew Chalk, Aug 5, 2003
    #9
  10. Andrew Chalk

    Ray at Guest

    In your IIS manager, pull up the properties of your site, or your
    application. Home directory tab. Configuration (under application
    settings). App debugging tab. Uncheck the debugging options.

    That's my guess, anyway.

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Andrew Chalk" <> wrote in message
    news:...
    > Response.Clear removes most of the extraneous bytes -- but still leaves
    >
    > <!--METADATA TYPE="ASP_DEBUG_INFO"
    > -->
    >
    > at the beginning.
    >
    Ray at, Aug 5, 2003
    #10
  11. Andrew Chalk

    Ray at Guest

    Perhaps this has to do with your debugging mode? Let's hope for that.

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Andrew Chalk" <> wrote in message
    news:%23Xkz$...
    > That link:
    >
    > > http://www.aspfaq.com/show.asp?id=2161

    >
    > is very interesting. Works like a champ -- except that it prefaces the
    > binary data with 3.5k of header bytes -- any idea why? I'm still looking
    > through the docs. on this.
    >
    > Regards,
    >
    > Andrew
    Ray at, Aug 5, 2003
    #11
  12. Andrew Chalk

    Andrew Chalk Guest

    Found the problem! I was running in debug mode within VI 6.0. That puts the
    header there and it can't be removed. Run it from localhost, or whatever,
    and the header disappears.

    Regards.

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > Perhaps this has to do with your debugging mode? Let's hope for that.
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Andrew Chalk" <> wrote in message
    > news:%23Xkz$...
    > > That link:
    > >
    > > > http://www.aspfaq.com/show.asp?id=2161

    > >
    > > is very interesting. Works like a champ -- except that it prefaces the
    > > binary data with 3.5k of header bytes -- any idea why? I'm still looking
    > > through the docs. on this.
    > >
    > > Regards,
    > >
    > > Andrew

    >
    >
    Andrew Chalk, Aug 5, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    1
    Views:
    2,451
  2. BLF
    Replies:
    4
    Views:
    1,278
    Mike Treseler
    Aug 7, 2004
  3. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    801
    John Carnahan
    Jul 18, 2003
  4. JuneCleaver

    Writing to a log file with in an aspx file.

    JuneCleaver, Apr 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,043
    Juan Romero
    Apr 8, 2004
  5. HNguyen
    Replies:
    4
    Views:
    2,401
    HNguyen
    Dec 21, 2004
Loading...

Share This Page