function that returns structre defined in another module

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

function that returns structre defined in another module

Post by ndudman »

Hi any help with the following, I'm trying to get the function abcd to return a structure which is defined in another module. I get the effor
  • >"C:\Program Files\ZBasic\zbasic.exe" --target-device=ZX24p --directory="Z:\home\ndudman\source\swapper/" --project="test2.pjt"
    Internal error: procedure.cpp(891), Rev 1263: missing user type information, "test2.bas" line 9
    >Exit code: 1

Code: Select all

structure abcS
	Dim a as byte
end structure

function abc() as abcS
	abc.a = 1
end function

function abcd() as myTimeModule.MyTimeStamp
	Dim ts as myTimeModule.MyTimeStamp
	myGetTime(ts)
	abcd = ts
end function

sub main()
	Dim ts as myTimeModule.MyTimeStamp
	Dim b as abcS = abc()
	Debug.print b.a
end sub
myTimeModule

Code: Select all

public Structure MyDate
      Public year as UnsignedInteger
      Public month as Byte
      Public day as Byte
End Structure
public Structure MyTime
      Public hour as Byte
      Public minute as Byte
      Public seconds as Single
End Structure
public Structure MyTimeStamp
      Public tdate as MyDate
      Public ttime as MyTime
      Private isCurrent as Boolean
End Structure

public sub myGetTime(byRef ts as MyTimeStamp)
	Call GetTimeStamp(ts.tdate.year, ts.tdate.month, ts.tdate.day, _
					  ts.ttime.hour, ts.ttime.minute, ts.ttime.seconds)
end sub


Thanks
Neil
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

I believe that you can avoid the error by omitting the module prefix, e.g.

Code: Select all

function abcd() as MyTimeStamp
   Dim ts as MyTimeStamp
   myGetTime(ts)
   abcd = ts
end function
Unrelated to this issue, note that it is not necessary to introduce the intermediate variable ts in this function. The following work equally well.

Code: Select all

function abcd() as MyTimeStamp
   myGetTime(abcd)
end function
- Don Kinzer
ndudman
Posts: 79
Joined: 25 December 2008, 14:00 PM

Post by ndudman »

Thanks very much on both points... its starting to make sense

Regards
Neil
Post Reply