Rev equiv of VB Type data handler

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
el_stupido
Posts: 24
Joined: Tue Jun 23, 2009 9:38 am

Rev equiv of VB Type data handler

Post by el_stupido » Thu Oct 15, 2009 3:02 pm

I am really keen to jump in to Run Rev having been a hypercard nut back in the day.

But when Hypercard pulled up stumps I somewhat reluctantly went back to VB.

One thing I can't work out from the manuals is how to make your own custom data types

ie in VB I'd do something like this:

Private Type Node
Row As Integer 'row of the actual node
Col As Integer 'column of the actual node
ParId As Integer 'parent node
ScoreF As Integer 'Score F (total cost)
ScoreG As Integer 'Score G (Cost of the path done)
ScoreH As Integer 'Score H (Estimated cost of the path to do)
Closed As Boolean 'indicates if the node is in the close list
End Type

then I could make an array in which each address in the array was the above custom data type, therefore giving me a very efficient way of storing a lot of info for each data element of the array

eg

Dim OpenList() as Node

I could also have different variables that are defined by this custom data type

Dim CurrNode as Node
Dim TargetNode as Node

And then pass data to the individual elements of the datatype:

TargetNode.Row = 34
TargetNode.Col = 25

....

So my question is...... How do I do something like this in Run Rev... It's basically arrays isn't it with sub arrays??

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Thu Oct 15, 2009 7:56 pm

Yep, nested arrays hold the answer.

Code: Select all

put "John" into tContact["firstname"]
put "Doe" into tContact["lastname"]
put tContact into tContacts[1]
put "Jane" into tContacts[2]["firstname"]
put "Smith" into tContacts[2]["lastname"]
It's a flexible system, but of course you have to make sure to use the right keys for each field. I tend to use the same name for the key as the column name in the underlying database.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Thu Oct 15, 2009 9:58 pm

...but you can't do anything like

Code: Select all

Dim CurrNode as Node
...sorry.

User-defined types would be very nice, and someday <sigh> we'll get them, but for now I just use nested arrays.

el_stupido
Posts: 24
Joined: Tue Jun 23, 2009 9:38 am

thanks

Post by el_stupido » Fri Oct 16, 2009 1:13 am

thanks for the quick feedback.

Arrays it is!

And yes, User-defined types would be very nice indeed. I love love love Hypertalk/Revscript... but there is beauty still in BASIC.

Heck user defined types have been in it since at QuickBASIC 4.0!!!

thanks again guys, I will start playing with arrays now

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 16, 2009 7:51 am

el_stupido,

The beauty of xTalk languages is that these languages are able to recognise data types by themselves. There is no need to define data types. I'd say that's very, very clever!

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

el_stupido
Posts: 24
Joined: Tue Jun 23, 2009 9:38 am

Post by el_stupido » Sat Oct 17, 2009 3:56 am

Mark wrote:el_stupido,

The beauty of xTalk languages is that these languages are able to recognise data types by themselves. There is no need to define data types. I'd say that's very, very clever!

Mark
Agreed, that is very clever.

I counter that sometimes making a data type is not so much for the benefit of the language itself but for the problem solving mind of the programmer.

It is for me anyway, but as has been noted, arrays are the key to this for me now.

I shall embrace arrays in due time I am sure.

Post Reply

Return to “Converting to LiveCode”