Storing many types of Variables

Just starting out? Need help? Post your questions and find answers here.
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

Storing many types of Variables

Post by SniffTheGlove »

Hi All,

How to store variables of different types in one way.

OK, I have lots of individual variables in my software
aa=1
ab=2
ac="Tree"
ad=4
ae="Roots"
af=12212.2
etc etc
but now looking to handle these variables in a better way. I first looked at an Array but you can not store different type in the array.
So then I looked at Map which I thought would do the job nicely but found out that you can not mix variable types.
So I looked at a list, but again not able to mix variable types.

So I then looked at Structure with Map. There are some examples in the help file and looks promising but type to add different variables works, ie I can store mixed variable type but not access them. Am I doing something wrong

Code: Select all

Structure Car
  Weight.l
  Speed.l
  Price.l
  Model.s
EndStructure

NewMap Cars.Car()

Cars("Ferrari F40")\Weight = 1000
Cars()\Speed = 320
Cars()\Price = 500000
Cars()\Model = "GT"

Cars("Lamborghini Gallardo")\Weight = 1200
Cars()\Speed = 340
Cars()\Price = 700000
Cars()\Model = "XY"

ForEach Cars()
  Debug "Car name: "+MapKey(Cars())
  Debug "Model: "+Str(Cars()\Model.s)  
  Debug "Weight: "+Str(Cars()\Weight)
  Debug "Speed: "+Str(Cars()\Speed)  
Next
Any suggestions. I am just looking for an easy way to bundle lots of variable into a single manageable way.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Storing many types of Variables

Post by Josh »

Look at line 22. You cannot convert a String to a String

Code: Select all

Structure Car
  Weight.l
  Speed.l
  Price.l
  Model.s
EndStructure

NewMap Cars.Car()

Cars("Ferrari F40")\Weight = 1000
Cars()\Speed = 320
Cars()\Price = 500000
Cars()\Model = "GT"

Cars("Lamborghini Gallardo")\Weight = 1200
Cars()\Speed = 340
Cars()\Price = 700000
Cars()\Model = "XY"

ForEach Cars()
  Debug "Car name: " + MapKey(Cars())
  Debug "Model: "    +        Cars()\Model
  Debug "Weight: "   + Str   (Cars()\Weight)
  Debug "Speed: "    + Str   (Cars()\Speed)  
Next
sorry for my bad english
SniffTheGlove
Enthusiast
Enthusiast
Posts: 122
Joined: Sat Nov 19, 2011 6:51 pm

Re: Storing many types of Variables

Post by SniffTheGlove »

Thanks

sorry for my bad coding :-)
Post Reply