News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Learning Data Type

Started by chanthorn, July 07, 2008, 10:16:38 PM

Previous topic - Next topic

chanthorn

Hi Guys,

I'm new in PB and I'm learning PB Language in the folder Tutorials. I got a problems in Data Type Example6, I have tried to followed the code and write a new one below. No error but the result come out was not correct. I can't find what's the problems, any body can help?

; PROJECT : Lesson10
; AUTHOR  : KIM Chanthorn
; CREATED : 7/6/2008
; EDITED  : 7/7/2008
; ---------------------------------------------------------------------

TitleScreen "Lesson 10 : Array Type"

Type PTel
   num$
   
EndType

Type PName
   first$
   last$
EndType



Type Person
   Name as PName
   mobile as PTel
   phone as PTel
EndType

Dim human(0) as Person

; start body
index = getFreeCell(human())

SetName(human(index).Name,"Chanthorn","KIM")
setTel(human(index).mobile,"092 952008")
setTel(human(index).phone,"023 212004")

index = getFreeCell(human())
SetName( human(index).Name, "Sotorn", "Sam" )
setTel( human(index).Mobile, "012 592652" )
setTel( human(index).phone, "023 311437" )

; show records back

for i = 1 to getArrayElements( human(), 1 )
   if human(i)
      showPerson( human(i).Person )
   endif
next


Sync
WaitKey

Function ShowPerson( me as Person Pointer )
   print ""
   Print "*** Person Detail ***"
   
   ShowName( me.Name, "Contact Name" )   
   showTel( me.mobile, "Mobile")
   showTel( me.phone, "Phone")
EndFunction
   

Function SetName(me as PName Pointer, f$, l$)
   me.first$ = f$
   me.last$ = l$
EndFunction

Function setTel(me as PTel Pointer, n$)
   me.num$ = n$
EndFunction

Function ShowTel( me as PTel Pointer, title$ )
   print title$+" : "+me.num$

EndFunction

Function ShowName( me as PName Pointer, title$ )
   print title$
   print "First Name : "+ me.first$
   print "Last Name : "+ me.last$
   
EndFunction
Jantorn Kim

kevin

#1
  From just a quick look, I think you've stumbled upon a bug that's creep into newer versions PB1.63.   The bug being that PB is passing the sub type (types within types) pointers incorrectly.  Which i think is why the results are dodgy.

  The code is actually correct (and should and used to work!) but PB isn't doing the correct thing in this case ATM...  I'll try and fix this for the next update..


chanthorn

Jantorn Kim

kevin