Contents in this wiki are for entertainment purposes only
This is not fiction ∞ this is psience of mind

Vintage VB6

From Catcliffe Development
Jump to navigation Jump to search


QuasiMatrix tertiary pair with a coincidentality-table supporting emergent computing

This is the VB6 header of the QuasiMatrix class —2023


'' File:         quasiMatrix.cls
'' Module name:  clsQuasiMatrix w/big(0) access, plus category membership
''               as the teriary data widget.
''
'' Copyright XenoEngineer@groupKOS.com 2023 All rights reserved.
''
'' Coding conventions:
''      CSV delimitation is used with text data files.
''      User defined data types (UDT) are used to organize all variables.
''      UDT data types are passed by reference to private class functions
''      as the first function parameter, emulating Lua-style receiver methods.
''
''      * Config filespec is programmatically assigned as appname.cfg.ini. (Class_Initialize)
''      * The data filespec (et al configuration) is restored from appname.cfg.ini.
''      * Coding convention: lower-case property names of configuration values are not persisted between runtime by this class.

Option Explicit ' Variable declaration required.

Public Event mxInitialized(msg As String)
Public Event mxLoaded(msg As String)
Public Event mxStructured(msg As String)
Public Event mxCombined(msg As String)
Public Event mxProgress(ByRef msg As String)
Public Event mxUnloaded(msg As String)


'' Constants for default class property values ''
Private Const DEF_FIELD_DELIMITER = ","     ' CSV field delimiter
Private Const DEF_ROW_DELIMITER = vbCrLf    ' CSV row delimiter

Private Const DEF_ROW_HEADER_NDX = 1
Private Const DEF_ROW_CHUNK = 1024
Private Const DEF_PAIRS_CHUNK = 256

Private Const DEF_AUTO_INIT = True
Private Const DEF_AUTO_EXIT = True
Private Const DEF_AUTO_LOAD = True
Private Const DEF_AUTO_STRUCTURE = True
Private Const DEF_AUTO_COMBINE = True
Private Const DEF_AUTO_UNATTENDED = True

Private Const DEF_DATA_FILESPEC_EXTANT = ".csv"

Private Const DEF_ATOMS_COLUMN_NDX = 1
Private Const DEF_LINKS_COLUMN_NDX = 2

Private Type udtAutomation
    AutoInit        As Boolean
    AutoLoad        As Boolean
    AutoStructure   As Boolean
    AutoCombine     As Boolean
    AutoExit        As Boolean
    Unattended      As Boolean: End Type

Private Type udtPerformance
    start   As Long
    finish  As Long
    lapsed  As Long: End Type

Private Enum enumMxStati
    '' Data processes ''
    enumMx0Uninitialized = 0
    enumMx1Initialized = 1
    enumMx2Loaded
    enumMx3Structured
    enumMx4AtomsLinksCombined
    End Enum

'' Coding convention: Only upper-case property names of class variables are
''                    persisted between runtimes ( with storeMx() and restoreMx() ) ''
Private Type udtMatrixNode
    '' Datum as a signed 32 bit integer (or a pointer to a data store of other data types)
    datum                   As Long
    '' Binary compared relationships
    greater                 As Long
    lesser                  As Long
    '' Trinary-equivalence natural-order relationships
    prev                    As Long
    next                    As Long
    '' Caching accelerators
    equivCount              As Long     ' Count cache increases per equivalence as an ordinal index of occurrence.
    first                   As Long
    last                    As Long
    End Type

Private Type udtMatrix
    node()                  As udtMatrixNode    ' Allocation-tests checks Ubound(data)
    nodeCount               As Long
    End Type

Private Type udtAtomLinkPair
    atom                    As Long
    link                    As Long
    End Type

Private Type udtQuasiMatrix                     ' Class data storage and properties
    CfgFileSpec             As String
    DataFileSpec            As String
    
    FieldDelimiter          As String           ' Delimits fields within a text line, defaulting to CSV delimiters.
    RowDelimiter            As String           ' Delimits text lines of a CSV file.
    rowBuffer()             As String
    
    RowHeaderNdx            As Long
    rowCount                As Long             ' Taken from atom channel, synchronous with the link channel.
    RowChunk                As Long             ' Storage array allocation chunck size.
    
    Pairs()                 As udtAtomLinkPair
    PairsChunk              As Long
    
    
    '' Data storage ''
    MXs()                   As udtMatrix
    mxCount                 As Long             ' Set in loadMX
    
    '' Conjecture selections ''
    AtomsColumnNdx          As Long
    LinksColumnNdx          As Long
    
    
    tsstart                 As Long             ' Time stamps.
    tsFinish                As Long
    tslapsed                As Long             ' Duration of timer ticks from start to tsFinish.
    
    cancel                  As Boolean          ' Checked intermittently during long iterations: Combinatoric generation per Atom-Link conjecture match.
    mxStatus                As enumMxStati
    End Type


Private mtQmx               As udtQuasiMatrix   ' Class UDT for the Prueitt Warehouse,renamed Matrix (of pointers), a pair of matrices support QAT analysis.
Private mtAuto              As udtAutomation    ' Class automation functions for multi-step process flow control.
Private mtPerf              As udtPerformance   ' Timer capture utility for timing performance.
Public mtMsgs               As VBA.Collection   ' Process messages with public access



Win32 wrapper code for VB6

'' File:         win32INI.bas
'' Module name:  modINI
'' Author:       XenoEngineer@groupKOS.com
'' Posted August 9, 2023 at https://groupKOS.com/dev
''
'' Description:  This module wraps VB6 around Win32 API methods to save/retreive data to an INI file by keyword by section.

Option Explicit

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpApplicationName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

' Loads the default variables from our private profile (INI file)

Public Function INIGetBool( _
                    ByVal fileSpec As String, _
                    ByVal Section As String, _
                    ByVal Key As String, _
                    Optional ByVal Default As String = "0" _
                    ) As Boolean
    Dim szBool       As String
    Dim lngLength    As Long
    
    '    Load Boolean options
    szBool = String$(6, Chr(0))
    lngLength = GetPrivateProfileString(Section, Key, Default, szBool, 5, fileSpec)
    szBool = Left$(szBool, lngLength)
    
    Select Case True
        
       Case Val(szBool) > 0, _
            LCase(szBool) = "true", _
            LCase(szBool) = "yes"
            
            INIGetBool = True
            
    End Select
End Function
 
Public Function INIGetInteger( _
                ByVal fileSpec As String, _
                ByVal Section As String, _
                ByVal Key As String, _
                Optional ByVal Default As String = "" _
                ) As Long
    On Error Resume Next
    
    Dim szStr As String
    Dim lngLength As Long
    
    szStr = String$(256, Chr(0))
    lngLength = GetPrivateProfileString(Section, Key, Default, szStr, 255, fileSpec)
    szStr = Left$(szStr, lngLength)
       
       
    If Val(szStr) > 0 Then
        INIGetInteger = CInt(szStr)
    Else
        INIGetInteger = 0
    End If
End Function

Public Function INIGetString( _
                    ByVal fileSpec As String, _
                    ByVal Section As String, _
                    ByVal Key As String, _
                    Optional ByVal Default As String = "" _
                    ) As String
    
   Dim szStr As String
   Dim lngLength As Long
   
   szStr = String$(256, Chr(0))
   
   ' Load szStr with the INI setting
   lngLength = GetPrivateProfileString(Section, Key, Default, szStr, 255, fileSpec)
   szStr = Left$(szStr, lngLength)
   
   INIGetString = szStr
End Function

Public Function INIGetSection( _
                    ByVal fileSpec As String, _
                    ByVal Section As String) As String()
                    
    '   Gets the entire section of Name=Value lines as an array of
    '   string values of lines within the section of the INI file.
    Dim strBuffer As String
    
    On Error Resume Next
    
    '   Read the INI section into the buffer string
    strBuffer = String$(2048, " ")
    strBuffer = Left$(strBuffer, GetPrivateProfileSection(Section, strBuffer, Len(strBuffer), fileSpec))
    strBuffer = Left$(strBuffer, Len(strBuffer) - 1)  'remove trailing null
    
    strBuffer = Replace(strBuffer, Chr$(0), vbCr)
    INIGetSection = Split(strBuffer, vbCr)
End Function
 
Public Sub INIDeleteSection( _
                    ByVal fileSpec As String, _
                    ByVal Key As String)
   Dim Result As Long
   Dim NullList As String
   
   NullList = Chr(0) & Chr(0)
   Result = WritePrivateProfileSection(Key, NullList, fileSpec)
   Debug.Assert Result <> 0
End Sub

Public Function INIWrite( _
                    ByVal fileSpec As String, _
                    ByVal Section As String, _
                    Optional ByVal Key As String = "", _
                    Optional ByVal Value As String = "" _
                    ) As Long
    
    '   Writes or deletes Key and Value
    
    Select Case True
        Case (Len(Key) > 0) And (Len(Value) > 0)
            INIWrite = WritePrivateProfileString(Section, ByVal Key, ByVal Value, fileSpec)
        Case (Len(Key) > 0) 'delete key's value
            INIWrite = WritePrivateProfileString(Section, ByVal Key, vbNullString, fileSpec)
        Case Else 'delete entire section
            INIWrite = WritePrivateProfileString(Section, vbNullString, vbNullString, fileSpec)
    End Select

End Function