Custom Resources
The "Big Deal" with custom resources is that you normally have to provide a way to process them in your program code. As Microsoft states it, "This usually requires the use of Windows API calls." That's what we'll do.
The example we'll use is a fast way to load an array with a series of constant values. Remember that the resource file is included into your project, so if the values that you need to load change, you'll have to use a more traditional approach such as a sequential file that you open and read. The Windows API we'll use is the CopyMemory API. CopyMemory copies block of memory to a different block of memory without regard to the data type that is stored there. This technique is well known to VB 6'ers as an ultra fast way to copy data inside a program.
This program is a bit more involved because first we have to create the a resource file containing a series of long values.
I simply assigned values to an array:
Dim longs(10) As Long
longs(1) = 123456
longs(2) = 654321
... and so forth.
Then the values can be written to a file called MyLongs.longs using the VB 6 "Put" statement.
Dim hFile As Long
hFile = FreeFile()
Open _
"C:\your file path\MyLongs.longs" _
For Binary As #hFile
Put #hFile, , longs
Close #hFile
It's a good idea to remember that the resource file doesn't change unless you delete the old one and add a new one. So, using this technique, you would have to update the program to change the values. To include the file MyLongs.longs into your program as a resource, add it to a resource file using the same steps described above, but click the Add Custom Resource ... instead of Add Icon ... Then select the MyLongs.longs file as the file to add. You also have to change the "Type" of the resource by right clicking that resource, selecting "Properties", and changing the Type to "longs". Note that this is the file type of your MyLongs.longs file.
To use the resource file you have created to create a new array, first declare the Win32 CopyMemory API call:
Private Declare Sub CopyMemory _
Lib "kernel32" Alias _
"RtlMoveMemory" (Destination As Any, _
Source As Any, ByVal Length As Long)
Then read the resource file:
Dim bytes() As Byte
bytes = LoadResData(101, "longs")
Next, move the data from the bytes array to an array of long values. Allocate an array for the longs values using the integer value of the length of the string of bytes divided by 4 (that is, 4 bytes per long):
ReDim longs(1 To (UBound(bytes)) \ 4) As Long
CopyMemory longs(1), bytes(0), UBound(bytes) - 1
Now ... this may seem like a whole lot of trouble when you could just initialize the array in the Form Load event, but it does demonstrate how to use a custom resource. If you had a large set of constants that you needed to initialize the array with, it would run faster than any other method I can think of and you wouldn't have to have a separate file included with your application to do it.