VB and VBA Users Source Code: Save a resource item to disk
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Save a resource item to disk
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, September 11, 2000
Hits:
690
Category:
Files/Directories/IO
Article:
VB6 allows you to create custom resources which are complied into the final executable (Check the VB 6 Resource Editor in the add-in manager). These resource files provide a convient location to keep files which are required by your application (eg databases or images). To save an item from a resource to disk, using the following code: 'Purpose : Saves resource item to a specified location. 'Inputs : sResourceName The name of the resource item. ' sResourceType The resource type (i.e. the name of the folder the resource ' item is located in. ' sToFile The name of the file where the resource is to be saved. 'Outputs : Returns 0 on success, error number on failure. 'Author : Andrewb 'Date : 11/09/2000 'Notes : eg. iRetVal = SaveResource(101, "CUSTOM", "C:\myImage.gif") 'Revisions : Public Function SaveResource(ByVal sResourceName As String, ByVal sResourceType As String, ByVal sToFile As String) As Long Dim abResourceData() As Byte Dim iFileNumOut As Integer On Error GoTo ErrFailed 'Retrieve the resource contents (data) into a byte array abResourceData = LoadResData(sResourceName, sResourceType) 'Get Free File Handle iFileNumOut = FreeFile 'Open the output file Open sToFile For Binary Access Write As #iFileNumOut 'Write the resource to the file Put #iFileNumOut, , abResourceData 'Close the file Close #iFileNumOut Exit Function ErrFailed: 'Failed to save resource file SaveResource = Err.Number End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder