Skip to main content

$Get Function

You use the $Get function to safely access a variable, whether or not it exists. If it exists, $Get returns its value. If it doesn't exist, $Get returns the empty string, or a string you specify as the second argument of $Get.

SAMPLES>write $get(fred)

SAMPLES>write $get(fred, 2)
2
SAMPLES>set fred = 1

SAMPLES>write $get(fred, 2)
1
SAMPLES>

Sometimes you want to access an array location, but you're not guaranteed that it exists. You can write code using If and $Data, but it's easier to use the $Get function to do this.

SAMPLES>set a(3) = "yes"

SAMPLES>set x = "no" if $data(a(3)) { set x = a(3) }

SAMPLES>write x
yes
SAMPLES>kill x

SAMPLES>set x = $get(a(3), "no")

SAMPLES>write x
yes
SAMPLES>
FeedbackOpens in a new tab