DYNAMIC

variable


should I use dynamic variable?

        Dynamic Variable is a DLL that makes data storage simple. My DLL makes storing information that uses various data types (e.g. string, boolean, long, or double). If all you want is to create a file that only uses strings (e.g. a playlist), don't use this program. It will take up space and save you only a little time. Also don't use this program if you want the user of your program to be able to edit the files your program will spit out with notepad, because they'll just get garbage if you use this. This DLL is meant for people who want to create a program that saves files in the same way that Microsoft Word might. Maybe each document will have its own settings, etc. In general Dynamic Variable is used in advanced programs that require binary input and output.

what are the elements of dynamic variable?

        Dynamic Variable has very few elements (i.e. methods, properties) and so functions similarly to a collection.

project.gif (132 bytes) DynamicVariable
        class.gif (162 bytes) DynamicVar The only class in the project. Must be declared "As New DynamicVar"
                method.gif (108 bytes) Add Adds a variable using the vbVarType structure as the only argument
                property.gif (119 bytes) AutoDetectVars A boolean representing whether or not a variable descriptor should be included
                method.gif (108 bytes) Clear Clear the current variables and their contents
                property.gif (119 bytes) Count Returns the number of variables
                method.gif (108 bytes) GetVars Gets a given number of variables from a file starting at a given position
                method.gif (108 bytes) PutVars Writes all the variables to a file starting at the beginning or end of a file
                method.gif (108 bytes) Remove Removes a variable from the list
                property default.gif (131 bytes) Value Sets/Returns the value of a variable in the list
                property.gif (119 bytes) VType Returns the type of the variable at the given index


add

object.Add    ByVal VarType As VbVarType, [ByVal Index As Double = -1]     As Double

VarType
    The following types are not supported: vbCurrency, vbDataObject, vbDecimal, vbEmpty, vbError, vbNull, vbObject, vbUserDefinedType

Index (optional)
    Where the variable will be inserted. 0 < Index < object.Count

Returns a Double value representing the index the variable was inserted at.

getvars

object.GetVars    ByVal sFileName As String, [ByVal VarCount As Double = -1], [ByVal StartPos As Long = 1]    As Long

sFileName
   
The path of the file to retrieve the variables from

VarCount (optional)
    Only get a certain number of variables (default goes until the end of the file)

StartPos (optional)
    Start at a given position (by byte, not variable)

Returns a Long value representing the position in the file that it stopped at.

putvars

object.PutVars    ByVal sFileName As String, [ByVal Append As Boolean = False]     As Long

sFileName
    The path of the file to write the variables to

Append (optional)
    Start at the end of the file or at the beginning

Returns a Long value representing the position in the file that it stopped at.

vtype

object.VType    ByVal Index As Double    As vbVarType

Index
    The index of the variable whose variable type you want

 

how does it work?

        Dynamic Variable uses the built in Get and Put statements and uses the Binary file mode. It does not lock the file for reading or writing. The most important setting is the AutoDetectVars boolean. A file saved using this will not open correctly when AutoDetectVars is false and vice-versa. When this is used an integer representing the type of a variable will precede it in the file.

For example, here is what a segment in a file might look like (where d is a descriptor byte, and v is variable data):

ddvvvvvvvvddvvddvvvvddvvvvvvvvvvvvvvvvvvvvvvvvvvddvvvv

It causes the file to be slightly longer, but it allows you to not initialize the variables in every instance of a DynamicVar class. This could be useful especially if you want to use Dynamic Variable for an option file. Instead of using the registry (which is not well supported in Visual Basic anyway) just write it to the disk.

        There are two arrays in my DLL, one a variant array and the other a vbVarType array. As a result the program does not make sure what you tell it one of the variables should be is the type that it is set for. It trusts that you can make sure that won't happen. Strings are a special case in this DLL. Because strings don't have a fixed memory length like a Long (4 bytes) or an Integer (2 bytes) the program has to write an integer value before the string specifying the length of the string. So using this with the last example, storing "they might be giants" to disk would look like this (where d is a descriptor byte, l is a length byte, and the rest is data):

ddllthey might be giantsddllthe matrix soundtrackddllriverdance

That's about all. Thank you for using Dynamic Variable. Please sent comments to Brian Donovan at maybeyoureinsane@hotmail.com.