Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Conundrum with a typed array + calls
#1
Ya, I'm back with another Q:
How can you make The.Array() hold its values and elements between calls?
Code:
Defint A-Z
Option Explicit
Type ArrayType
   X As Integer
   Y As Integer
   Z As Integer
End Type
Type TheType
   A as Integer
   Array(0) As ArrayType
End Type
Declare Sub Add(The As TheType)
Declare Sub Display(The As TheType)
Dim The As TheType
Add The
Display The
Sleep
Sub Add (The As TheType)
   Redim The.Array(234) As ArrayType
   The.Array(34).X = 30
   ? ubound(The.Array)
End Sub
Sub Display (The As TheType)
   ? The.Array(34).X
   ? Ubound(The.Array)
End Sub
i]"But...it was so beautifully done"[/i]
Reply
#2
you cant do dynamic arrays in udts, you have to use pointers like..


Code:
Defint A-Z
Option Explicit
Type ArrayType
   X As Integer
   Y As Integer
   Z As Integer
End Type
Type TheType
   A as Integer
   Array As ArrayType ptr
End Type

Declare Sub Add(The As TheType)
Declare Sub Display(The As TheType)


Dim The As TheType

the.array = callocate(len(arraytype))


Add The

Display The

Sleep

Sub Add (The As TheType)
   The.Array = reallocate(The.Array, (234)  * len(ArrayType))
   The.Array[34].X = 30

End Sub

Sub Display (The As TheType)
   ? The.Array[34].X

End Sub
Reply
#3
Thank you very much again Big Grin
i]"But...it was so beautifully done"[/i]
Reply
#4
Ok, another Q.
How do you use that with Ubound?
i]"But...it was so beautifully done"[/i]
Reply
#5
as far as i know you cant, i always keep another var to store how many structures are pointed to like "numofarrays"... len wont work because the pointer itself is an integer, returning 4
Reply
#6
Ok, thnx.
i]"But...it was so beautifully done"[/i]
Reply
#7
Couldn't there be possibility of storing array descriptor pointer into UDT and then use classic array management functions to acess this array?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)