How can I get OnError to repeat the line/command?
Posted: 06 May 2024, 02:57
In this example, var1 is initially unset, so msgbox var1 throws an error.
I use OnError to automatically detect that var1 was unset and then give it a value of "hey".
But I still need the script to actually show a messagebox with "hey". Instead, the script proceeds to the next line, msgbox "box2". So no messagebox "hey" was shown.
I understand that this is the intended behaviour of OnError, but is there a way to repeat msgbox var1 anyway?
(Ideally, I want to use OnError in my actual script, so that when a variable is unset, I'll use the ErrFuncObj to call an InputBox to manually key in and assign a value to the unset variable. When this happens, I'll need the script to re-run the same line, but do it with my newly set variable.)
I use OnError to automatically detect that var1 was unset and then give it a value of "hey".
But I still need the script to actually show a messagebox with "hey". Instead, the script proceeds to the next line, msgbox "box2". So no messagebox "hey" was shown.
I understand that this is the intended behaviour of OnError, but is there a way to repeat msgbox var1 anyway?
Code: Select all
myfunc()
myfunc()
{
static var1
OnError ErrFuncObj
msgbox var1
msgbox "box2"
ErrFuncObj(ErrorObj, Mode)
{
if ErrorObj is UnsetError
{
msgbox "UnsetError yo"
var1 := "hey"
}
else
{
throw ErrorObj
}
return -1
}
}