I'm trying to trigger an error on purpose and then continue my script.
Error number -2700
triggers an "Unkown Error" error but it also ends the script with the returning value of -2700 instead of 0.
Also, I don't want the script to end after the error but to continue when you press the "OK" button.
The reason I want to do this is so that I won't have to make an Error dialog in every language myself.
Help?
(The comments mess up my code, that's why I post a new answer)
"For each language" sounds strange. Normally, you programme in a particular language and you'd write an error handling routine. In AppleScript this would be
try
-- your script here
on error errMsg number errNum
errorHandler(errMsg,errNum)
end try
on errorHandler (errMsg,errNum)
display dialog errMsg & " (" & errNum & ")."
end errorHandler
Try:
try
1 / 0
on error errMsg number errNum
tell me
activate
display alert errMsg & return & return & errNum buttons "OK"
end tell
end try
beep 3
Related
I've been scrubbing google to find a quick reference for macro coding in Attachmate extra! unsuccessfully. Could someone point me to a URL to learn what I need to know, tell me how to resolve the code below or both.
I took a "Hello World" example and a recorded macro and mushed the below code together, which does what i need with a couple exceptions.
Dim dlgHello as HelloDialog 'Declare the dialog file.
nRet = Dialog (dlgHello)
Select Case nRet 'dlgHello.AllButtons
Case - 1 ' OKButton
Sess0. Screen. Sendkeys ("Show a60:4aug;a")
Sess0. Screen. Sendkeys("<Enter>")
Sess0. Screen.WaitHostQuiet (g HostSettleTime)
System. Timeoutvalue = OldsystemTimeout
Msabox "Done"
Case 0 ' CancelButton
Msgbox "Goodbye! "
End Select
While this code above works, I need to change it to pull system date and subtract two days.
Original code Sess0. Screen. Sendkeys ("Show a60:4aug;a")
Instead of the static 4aug, I need the code to pull the system date then subtract two days.
My failed attempt was Sess0. Screen. Sendkeys ("Show a60:"Today() -2"a")
Would be grateful if anyone could tell me how to resolve this and also point me to a good learning resource. Thanks
I received a working solution from Tom F in the MicroFocus community. Solution below.
Sub Main
Dim myDate
myDate=CVar(Date)-2
myDate = Format(myDate, "dmmm")
End Sub
https://portal.microfocus.com/s/article/KM000008384?language=en_US
There is data validation in my MS Word user form which returns the focus to the textbox where the user entered something incorrect. Now I am trying to accommodate the user's change of mind: instead of correcting the entry, I want him to be able to exit the form (click the Exit command button), in which case the entry would be discarded. I suppose that a solution would start with not using the text box's exit event. I little help from someone who knows the answer would save me a lot of testing time, perhaps to find out that I can't do it.
Does anyone know?
I understand that you are handling the Exit event of the Textbox, setting the Cancel output parameter if the data is not valid.
There's a tricky but simple solution that permits to keep that working and still have an Exit button. It permits to activate the handler of the Exit button without requiring the focus to leave the Textbox. This way you can unload the Form safely in this handler.
Try this it works pretty smoothly:
1- Set the property TakeFocusOnClick of the Exit command button to False. You can do that at design time in the property-sheet, or at run-time i.e. at UserForm_Activate
2- just unload the form when the Exit button is clicked:
Private Sub ExitButton_Click()
Unload Me
End Sub
#A.S.H provided the key to the solution below. His point is that it is possible to call another event procedure while Cancel is active in the Exit procedure of a control. That other procedure can be used to rectify the condition in the first control which is triggering the Cancel, thereby enabling an orderly exit. The all-enabling condition is that the control on whose click event the rectifying procedure is to run must not take the focus when clicked (meaning it can run without triggering an exit from the control stuck on Cancel). I have added code to the exit procedure to set CmdExit.TakeFocusOnClick = False when a Cancel condition arises there. Now, ...
Private Sub CmdExit_Click()
' 12 May 2017
' if CmdExit can't take the focus it can't be the ActiveControl
If Not ActiveControl Is CmdExit Then
Select Case ActiveControl.Name
Case "Cbx107"
Cbx107.Value = ""
Case "Tbx53"
Tbx53.Value = "0"
End Select
With CmdExit
If Not .TakeFocusOnClick Then
.TakeFocusOnClick = True
.SetFocus
End If
End With
End If
' now CmdExit is the ActiveControl
MsgMe "Cmd Exit: ActiveControl = " & ActiveControl.Name
Me.Hide
End Sub
I'm struggling to propagate an system error object from a UI trigger to the main program.
ON CHOOSE OF btnButton IN FRAME frmFrame
DO:
/* this will cause a system error */
FIND FIRST Customer NO-LOCK
WHERE Customer.CustNum = 1875918759178.
CATCH eErr AS Progress.Lang.SysError:
/* It does get caught over here */
UNDO, THROW eErr.
END CATCH.
END.
CATCH eMain AS Progress.Lang.SysError:
/* this message doesn't happen */
MESSAGE
"caught"
VIEW-AS ALERT-BOX.
END CATCH.
It doesn't seem to want to propagate the error object though. Any ideas?
From the documentation on THROW option, Undo Statement:
"UNDO, THROW is not allowed in a CATCH block of a user interface trigger. The ABL does not you to raise or RETURN error out of a user interface trigger. To do so will result in a compile-time error. "
The sentence above says "Does not you to..." I believe it should be "does not allow you to". But the documentation itself is wrong.
Anyway, it seems what you're trying to accomplish is not yet possible as of today (Dec,27,2016).
Try using NO-ERROR on the end of the FIND statement:
FIND FIRST Customer NO-LOCK
WHERE Customer.CustNum = 1875918759178 NO-ERROR.
Then you can use the ERROR-STATUS system handle to catch the error:
MESSAGE ERROR-STATUS:ERROR SKIP
ERROR-STATUS:GET-MESSAGE(1)
VIEW-AS ALERT-BOX.
That error status should be set until some other statement executes with NO-ERROR. You can also use AVAILABLE(Customer) to see if the record was found:
MESSAGE AVAILABLE(Customer) VIEW-AS ALERT-BOX.
I am trying to throw an error (user defined and not the netLogo runtime error ) if one button is pressed before the other.
I have three buttons " SETUP" , "CONFIGURE", " SIMULATE" . I want to throw an error if SIMULATE is clicked before CONFIGEURE.
I know there is a primitive available " user-message" as mentioned by Sir.Seth Tisue in my other question, but do not know how to include it for my situaton.
Make a global configured?. Have configure set it to true. Then in simulate, put:
if configured? != true [
user-message "You must press configure first"
stop
]
I'm trying to write an AppleScript for use with Mail (on Snow Leopard) to save image attachments of messages to a folder. The main part of the AppleScript is:
property ImageExtensionList : {"jpg", "jpeg"}
property PicturesFolder : path to pictures folder as text
property SaveFolderName : "Fetched"
property SaveFolder : PicturesFolder & SaveFolderName
tell application "Mail"
set theMessages to the selection
repeat with theMessage in theMessages
repeat with theAttachment in every mail attachment of theMessage
set attachmentFileName to theAttachment's name
if isImageFileName(attachmentFileName) then
set attachmentPathName to SaveFolder & attachmentFileName
save theAttachment in getNonexistantFile(attachmentPathName)
end if
end repeat
end repeat
end tell
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
When run, I get the error:
error "Mail got an error: Can’t continue isImageFileName." number -1708
where error -1708 is:
Event wasnt handled by an Apple event handler.
However, if I copy/paste the isImageFileName() into another script like:
property ImageExtensionList : {"jpg", "jpeg"}
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
if isImageFileName("foo.jpg") then
return true
else
return false
end if
it works fine. Why does Mail complain about this?
It may be a quirk, but it has an explanation. If you're in a tell application "whatever" block, all calls are made in the namespace of that application's dictionary, not your script's dictionary. Because of that, you have to explicity tell AppleScript to look back into your script for the name. Saying my is like saying tell me, instructing the script where to look for the function.
Try "my isImageFileName". It's not Mail, just a quirk of AppleScript.