Keeping Datatypes Correct with Variables

OK, in Visual Basic you do something like ‘Option Explicit’ to make sure your variables stay what they are declared as (string, integer, etc) and that you don’t assign the wrong datatype to a variable. Can you keep your variable declrations/assignments “honest” or correct in AppleScript?

Hi, Kurty.

No. You can declare them as locals, globals, or properties, but you can assign any class of data to them at any time.

You could define your own methods if you feel better… Eg:

global varX

set varX to {class:integer, data:0} --> initialize

try
	set varX to checkVar(varX, 7)
end try

try
	set varX to checkVar(varX, "foo")
end try

varX --> {class:integer, data:7}

to checkVar(v, dat)
	if v's class is dat's class then return {class:v's class, data:dat}
	error
end checkVar