Code Examples
  Home arrow Code Examples arrow Page 2 - Binary File, Array Scripting Secrets
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Binary File, Array Scripting Secrets
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2009-03-25

    Table of Contents:
  • Binary File, Array Scripting Secrets
  • Writing Binary Files with the FileSystemObject
  • Removing an array element
  • Adding Voice to Your Scripts

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Binary File, Array Scripting Secrets - Writing Binary Files with the FileSystemObject


    (Page 2 of 4 )

    Writing Binary Files – Method 2 (FileSystemObject)

    I used the ADODB.Stream method of creating binary files for quite a while before stumbling onto this next solution.  The idea was originally published by Eric Phelps, but unfortunately I don’t have a link to that.

    While the ADODB method is effective, it does have one major drawback.  Each file has to be written to disk twice.  While this is a fairly quick process, just knowing that it was happening made the method seem inefficient to me.  This method doesn’t post that problem.

    strPath = "C:Zip.zip"

     

    Const ForWriting = 2

    Set objFso = CreateObject("Scripting.FileSystemObject")

    With objFso.OpenTextFile(strPath, 2, True)

       For x = 1 To 44 Step 2

          .Write Chr(Clng("&h" & Mid("504B0506000000000000000000000000000000000000",x,2)))

       Next

       .Close

    End With

    This method exploits the FileSystemObject’s ability to create an empty file on disk.  The OpenTextFile method has an optional third parameter that, when set to true, will create a new file on disk if the specified file doesn’t already exist.  This file is created without any contents.  It’s just an empty shell.  Writing binary data directly to that file would accomplish the task at hand.

    The method uses an interesting manner to write the binary data.  A string of byte characters is read in a For loop, two characters at a time.  A “&h” is then added to the beginning of the two-character string.  You may recognize this as VBS’s way of explicitly writing hexadecimal values.

    The string containing the hex value is then converted to a decimal number with the Clng function.  Once you have a decimal representation of the binary character, it can be written directly to the file with the Chr function.

    More Code Examples Articles
    More By Nilpo


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek