I was bored so I made this.
#1
This is a dynamic array that resizes itself as you add to or remove from it.
each entry has 2 properties: whichType and Content.
whichType tells what kind of variable is stored, and Content is what the variable contains.
whichType is a _byte and content is always a string. variables are converted to/from strings by the subs/functions.
here is the code, maybe it might be useful:

Code: (Select All)
Option _Explicit

Type Limits
    Minimum As _Byte
    Maximum As _Unsigned _Integer64
    Current As _Unsigned _Integer64
End Type

Type Entry 'global array
    whichType As _Byte
    Content As String
End Type

Dim Shared theLimit As Limits
ReDim Shared theBase(theLimit.Minimum) As Entry
'
theLimit.Minimum = 0
theLimit.Maximum = 0 - 1
'
theLimit.Current = theLimit.Minimum

' End Declarations

Dim test1%%
Dim test2&&
Dim test3~&&
Dim test4##
Dim test5$

add_byte 54
test1%% = get_byte(theLimit.Current)
Print test1%%

add_int 1444443893487
test2&& = get_int(theLimit.Current)
Print test2&&

add_uint 45989379879387398734987
test3~&& = get_uint(theLimit.Current)
Print test3~&&

add_float 80982.39802
test4## = get_float(theLimit.Current)
Print test4##

add_str "boom!"
test5$ = get_str(theLimit.Current)
Print test5$


' Begin modules

Function trim$ (theInput As String)
    trim = LTrim$(RTrim$(theInput))
End Function

Sub add_byte (theInput As _Byte)
    add_Item
    theBase(theLimit.Current).Content = trim$(Chr$(theInput))
    theBase(theLimit.Current).whichType = 1
End Sub

Sub add_int (theInput As _Integer64)
    add_Item
    theBase(theLimit.Current).Content = trim$(_MK$(_Integer64, theInput))
    theBase(theLimit.Current).whichType = 2
End Sub

Sub add_uint (theInput As _Unsigned _Integer64)
    add_Item
    theBase(theLimit.Current).Content = trim$(_MK$(_Unsigned _Integer64, theInput))
    theBase(theLimit.Current).whichType = 3
End Sub

Sub add_float (theInput As _Float)
    add_Item
    theBase(theLimit.Current).Content = trim$(_MK$(_Float, theInput))
    theBase(theLimit.Current).whichType = 5
End Sub

Sub add_str (theInput As String)
    add_Item
    theBase(theLimit.Current).Content = trim$(theInput)
    theBase(theLimit.Current).whichType = 7
End Sub

Sub add_Item
    theLimit.Current = theLimit.Current + 1
    ReDim _Preserve theBase(theLimit.Current) As Entry
End Sub

Function get_byte%% (Selector As _Unsigned _Integer64)
    get_byte = Asc(theBase(Selector).Content)
End Function

Function get_int&& (Selector As _Unsigned _Integer64)
    get_int = _CV(_Integer64, theBase(Selector).Content)
End Function

Function get_uint~&& (Selector As _Unsigned _Integer64)
    get_uint = _CV(_Unsigned _Integer64, theBase(Selector).Content)
End Function

Function get_float## (Selector As _Unsigned _Integer64)
    get_float = _CV(_Float, theBase(Selector).Content)
End Function

Function get_str$ (Selector As _Unsigned _Integer64)
    get_str = trim$(theBase(Selector).Content)
End Function

Sub rm_byte (Selector As _Unsigned _Integer64)
    theBase(Selector).whichType = 0
    theBase(Selector).Content = ""
    Dim rm_global_B_inc
    For rm_global_B_inc = Selector To theLimit.Current - 1
        theBase(rm_global_B_inc).whichType = theBase(rm_global_B_inc + 1).whichType
        theBase(rm_global_B_inc).Content = theBase(rm_global_B_inc + 1).Content
    Next rm_global_B_inc
    rm_Item
End Sub

Sub rm_int (Selector As _Unsigned _Integer64)
    theBase(Selector).whichType = 0
    theBase(Selector).Content = ""
    Dim rm_global_I_inc
    For rm_global_I_inc = Selector To theLimit.Current - 1
        theBase(rm_global_I_inc).whichType = theBase(rm_global_I_inc + 1).whichType
        theBase(rm_global_I_inc).Content = theBase(rm_global_I_inc + 1).Content
    Next rm_global_I_inc
    rm_Item
End Sub

Sub rm_uint (Selector As _Unsigned _Integer64)
    theBase(Selector).whichType = 0
    theBase(Selector).Content = ""
    Dim rm_global_UI_inc
    For rm_global_UI_inc = Selector To theLimit.Current - 1
        theBase(rm_global_UI_inc).whichType = theBase(rm_global_UI_inc + 1).whichType
        theBase(rm_global_UI_inc).Content = theBase(rm_global_UI_inc + 1).Content
    Next rm_global_UI_inc
    rm_Item
End Sub

Sub rm_float (Selector As _Unsigned _Integer64)
    theBase(Selector).whichType = 0
    theBase(Selector).Content = ""
    Dim rm_global_F_inc
    For rm_global_F_inc = Selector To theLimit.Current - 1
        theBase(rm_global_F_inc).whichType = theBase(rm_global_F_inc + 1).whichType
        theBase(rm_global_F_inc).Content = theBase(rm_global_F_inc + 1).Content
    Next rm_global_F_inc
    rm_Item
End Sub

Sub rm_str (Selector As _Unsigned _Integer64)
    theBase(Selector).whichType = 0
    theBase(Selector).Content = ""
    Dim rm_global_S_inc
    For rm_global_S_inc = Selector To theLimit.Current - 1
        theBase(rm_global_S_inc).whichType = theBase(rm_global_S_inc + 1).whichType
        theBase(rm_global_S_inc).Content = theBase(rm_global_S_inc + 1).Content
    Next rm_global_S_inc
    rm_Item
End Sub

Sub rm_Item
    theLimit.Current = theLimit.Current - 1
    ReDim _Preserve theBase(theLimit.Current) As Entry
End Sub
Reply




Users browsing this thread: 1 Guest(s)