by Jan Philip Matuschek (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
This is a fast way to write a resource to a file. UPDATE: You can find an example to this code here">https://www.vbcoders.com/xq/ASP/txtCodeId.23155/lngWId.1/qx/vb/scripts/ShowCode.htm">here.
Inputs
Filename - Path to the output file, ResID - ID of the resource to write, ResType - Type of the resource to write, Overwrite - Overwrite the output file if it already exists
Public Sub ResToFile(Filename As String, ResID As Variant, ResType As Variant, Optional Overwrite As Boolean = False)
Dim Buffer() As Byte
Dim Filenum As Integer
If Dir(Filename) <> Empty Then 'Check if output file already exists
If Overwrite Then Kill Filename Else Err.Raise 58
End If
Buffer = LoadResData(ResID, ResType) 'Load the resource into a byte array
Filenum = FreeFile
Open Filename For Binary Access Write As Filenum
Put Filenum, , Buffer 'Write the entire array into the file
Close Filenum
End Sub