I'm considering porting a large PowerBasic program to FB. But I need to handle nested arrays of UDT structures. I've been playing with a trial structure to get the syntax correct, but I can't get it to work.
Here's where I sit, and I've tried all kinds of variations of pointer coding, but none work. The example just loads an array within a single UDT structure and then prints it out. Can anyone give me a hint. Is it even possible?
type LModel
LTxt as string
end type
type TabModel
L(1 to 10) as LModel
end type
dim TabTable(1 to 5) as TabModel
Dim TP as TabModel ptr
dim as long i, j
j = 1
TP = @TabTable(j)
for i = 1 to 10
*TP->L(i).LTxt = str$(i)
next i
for i = 1 to 10
print *TP->L(i).LTxt
next i
Sleep
type LModel
LTxt as string
end type
type TabModel
L(1 to 10) as LModel
end type
dim TabTable(1 to 5) as TabModel
Dim TP as TabModel ptr
dim as long i, j
j = 1
TP = @TabTable(j)
for i = 1 to 10
TP->L(i).LTxt = str(i)
next
for i = 1 to 10
print TP->L(i).LTxt
next
Sleep
You do understand how pointers work, yes? If not, have a look at the FreeBasic Manual for a primer on their usage:
type LModel
LTxt as string
end type
type TabModel
L(1 to 10) as LModel
end type
dim TabTable(1 to 5) as TabModel
dim as long i, j = 1
for i = 1 to 10
TabTable(j).L(i).LTxt = str(i)
next
for i = 1 to 10
with TabTable(j)
print .L(i).LTxt
end with
next
Sleep
Mostly personal preference, but I think that it is easier to make errors with pointers.
Paul: Yes, I understand pointers, it's syntax differences between PB and FB that are catching me. But why doesn't TP need the * in front, or is that implied by the -> syntax?