multi arrays of custom structures with basic functions ; my easy way

Windows specific forum
xpectmore
User
User
Posts: 15
Joined: Thu Jul 29, 2021 12:52 pm

multi arrays of custom structures with basic functions ; my easy way

Post by xpectmore »

use it how you like , is a FTM license = FREE TO MANKIND

Code: Select all

IncludeFile "inc.pbi"

Structure Person
    FirstName.s
    LastName.s 
    Age.w 
EndStructure

initKEYS(Person)

;clearKEYS(Person);cause initKEYS happened i do not need this
  ;Debug getKEYbyPOS(Person, 110 ,age);<---(just in case error example:uncomment by removing ; to test it)array index out of bounds.. the index 110 doesn't exist!!!
  newKEY(Person) 
  newKEY(Person)
  
  Debug "i count: "+count(Person)+" elements"
  
  
;clearKEYS(Person)
  newKEY(Person)
  newKEY(Person)
  newKEY(Person)
  newKEY(Person)
  Debug "i count: "+count(Person)+" elements"
  
  
  
  ;PersonKEYS(0)\name="da"
  setrowKEYS(person,0,firstname,"Basic")
  setrowKEYS(person,0,lastname,"Pure")
  Debug "OH YEAH ! "+getKEYbyPOS(Person, 0 ,lastname)+getKEYbyPOS(Person, 0 ,firstname) + "isn`t C/C++ !!!";Debug(PersonKEYS(0)\name)
  
  setrowKEYS(person,0,age,21) ; 2021-2000 :)
  Debug "and this guy is so old: "+getKEYbyPOS(Person, 0 ,age)  
  
  
  
  
  
  Debug "---------------------------------------------"
  Debug "Let`s try quick new custom structure.."
  Debug "i already had      IncludeFile ``inc.pbi``  first"
  
  Structure Brand
    BrandName.s
    Comment.s 
  EndStructure
  
  
  Debug "we manage another array !!!"
  initKEYS(Brand)
  
  
  newKEY(Brand)
  setrowKEYS(Brand, 0 ,BrandName,"ASUS")
  setrowKEYS(Brand ,0 ,Comment,"laptops")
  
    
  newKEY(Brand)
  setrowKEYS(Brand , 1 ,BrandName,"ACER")
  setrowKEYS(Brand , 1 ,Comment,"laptops,tablets")
  
    
  
  Debug "i count: "+count(Brand)+" elements"
  
  Debug "row(0): "+getKEYbyPOS(Brand, 0 ,BrandName)+" Comment: " +getKEYbyPOS(Brand, 0 ,Comment)
  Debug "row(1): "+getKEYbyPOS(Brand, 1 ,BrandName)+" Comment: " +getKEYbyPOS(Brand, 1 ,Comment)
  
  ;Debug "row(1000): "+getKEYbyPOS(Brand, 1000 ,BrandName)+" Comment: " +getKEYbyPOS(Brand, 1000 ,Comment)
  ;\____uncomment that will trigger the same error .. we do not have the index 1000 !
  


and the inc.pbi :


Code: Select all

Macro initcount(datatype)
  Global datatype#count=0
EndMacro

Macro initKEYS(datatype)
  Global datatype#count=0
  Global Dim datatype#KEYS.datatype(0)
EndMacro


Macro newKEY(datatype)
  Debug "new.. "+datatype#count 
  datatype#count = datatype#count + 1
  ReDim datatype#KEYS(datatype#count)
EndMacro
  
Macro clearKEYS(datatype) 
  Debug "Clearing custom Array() of stucture"
  datatype#count=0
  Global Dim datatype#KEYS.datatype(0)
EndMacro


Macro count(datatype)
  datatype#count
EndMacro


Macro setrowKEYS(datatype ,position, key ,value )
  datatype#KEYS(position)\key=value
EndMacro

Macro getKEYbyPOS(datatype , position , key)
 datatype#KEYS(position)\key
EndMacro