u dnt need to use $did($dname,1) while ur in the dialog sub...just $did(1),in the variable set... here
elseif ($did == 3) && (%haerma == off) { set %haerma on }
will be better and shorter in code if its like :
elseif ($did == 3) && (!%haerma) { set %haerma 1}
u dnt need to set on and off...just any value and check if the variable isnt null .... like what u did here :
if (%haerma == on) { did -c $dname 3 }
if (%haerma == off) { did -u $dname 3 }
u should have done it like :
if (%haerma) { did -c $dname 3 }
else { did -u $dname 3 }
otherthan this its workin properly..btw u wrote a variable in a wrong way in that line :
if ($did == 7) { unset %herma | unset %hkanal | unset %hnick }
replace %herma...goodluck