I have an old application built in Visual Foxpro 9. I want to terminate the form without executing remaining code. Form.Release event release the form after executing remaining code in event it called from. I want to use this when any error occurred, can anyone please help?
I may have other forms open and dont want to close other forms in event of error on one form. Cancel would close all open forms, so I cant use it.
Main.Prg
On Error Do ErrHandle With Error( ), Message( ), Program( ), Lineno( )
Do Form form1
Do Form form2
Do form formN
Read Events
Procedure ErrHandle(tnerror, tcMessage, tcProg, tnLineNo)
Local lcError
TEXT to m.lcError textmerge noshow
Error No: << m.tnerror >>. Message: << m.tcMessage >>
Source: << m.tcProg >> at line << m.tnLineNo >>
ENDTEXT
Messagebox(m.lcError, 0+4096, "Error", 5000)
Local loForm
loForm = _vfp.ActiveForm
If !Isnull(m.loForm)
m.loForm.Release()
Endif
Endproc
This would just release the active form.
Main.prg
Do Form form1
Do Form form2
Do form formN
Read Events
Errhandle.prg
lparameters tnerror, tcMessage, tcProg, tnLineNo
Local lcError
TEXT to m.lcError textmerge noshow
Error No: << m.tnerror >>. Message: << m.tcMessage >>
Source: << m.tcProg >> at line << m.tnLineNo >>
ENDTEXT
Messagebox(m.lcError, 0+4096, "Error", 5000)
Form method where error is expected:
Local loForm
loForm = thisform
On Error ;
return ErrHandle(Error( ), Message( ), Program( ), Lineno( )) ;
and m.loForm.Release()
local lc
lc = "Hello"
If m.lc = 1 && explicit error
EndIf
_screen.Caption = "This code wouldn't run"
On Error
Note: This is sort of using try ... catch blocks. I personally don't use try ... catch because unlike on error it doesn't catch all errors.
On the Form's Error event place the following code:
LPARAMETERS nError, cMethod, nLine
*Handle the error/ clean up/ MessageBox / Log error to file or table / etc.
thisform.release
RETURN TO MASTER
** Hope this helps
Related
I've got an AutoIt script that goes to a website, logs in, and navigates to another page. But _IENavigate is throwing an error that isn't in the documentation . The output to the following code is: "Here is what the flag is: -1 and the error flag is: 0"
But you'll see in the documentation that only error codes 1-9 exist, there is no flag for #error = 0...
I do notice that the browser does navigate to the second page but when I try getting all the tags on the page, it doesn't find them. Please help! :)
Local $oIE = _IE
Create("http://www.example.com/")
_IELoadWait($oIE)
Local $j_username = _IEGetObjByName($oIE, "username")
_IEFormElementSetValue($j_username, $sUser)
Local $j_password = _IEGetObjByName($oIE, "password")
_IEFormElementSetValue($j_password, $sPass)
Local $login_submit = _IEGetObjByName($oIE, "button")
_IEAction($login_submit, "click")
_IELoadWait($oIE)
$iFlag = _IENavigate($oIE, "http://www.example.com/page2", 1)
ConsoleWrite( "Here is what the flag is: " & $iFlag & " and the error flag is: " & #error & #CRLF)
_IELoadWait($oIE)
Turns out the documentation says:
This function always returns a value of -1. This is because the navigate method has no useful return value and therefore nothing can be implied from it.
It's a feature, not a bug. :)
Set ParentObject=Browser("Title:=Sign-In").Page("Title:=Sign-In Home Page")
PropertyRequired="name"
PropertyValue="Agree and Login"
Result="yes"
Function WebButton(ParentObject,PropertyRequired,PropertyValue,Result)
Call ReportResult(Result)
Dim hit
hit=0
If PropertyRequired="" then
PropertyRequired="name"
End If
If ParentObject.WebButton(PropertyRequired &":="&PropertyValue).exist then
ParentObject.WebButton(PropertyRequired &":="&PropertyValue).click
hit=1
End if
If hit>0 then
Reporter.reportevent micpass,"The button: "&PropertyValue,"Clicked sucessfully"
else
Reporter.reportevent micpass,"The button: "&PropertyValue,"not Clicked sucessfully"
End if
End Function
After I Call this function, then an error " Wrong number of arguments or invalid property assignments" displayed.
Call WebButton(ParentObject,PropertyRequired,PropertyValue,Result)
I just executed your piece of code .I dont find any issues .
Try using parenthesis when calling Reporter.reportevent so it's like this:
Reporter.reportevent (micpass, "The button: " & PropertyValue, "Clicked sucessfully")
Although I found similar problems none could provide a sufficient answer to my problem.
I came across an older VBScript that is used for communication and synchronization with Outlook. Somebody (not me) gets a strange error when running the script:
Script:
"Some path"
Line: 286
Character: 9
Error: Invalid process or invalid argument
Code: 800A0005
Source: Runtime Error in VBScript
Now what I want to know is WHY that error occurs. Just a general interpretation of the error. But first here is the relevant code:
Set refnum = open_outputfile(outputfileverz & outputfilename_short)
If (errcode = 0) Then
If (check_textfile(refnum)) Then
refnum.WriteLine (strOutput)
errcode = close_outputfile(outputfileverz & outputfilename_short, outputfilename_short, refnum)
If (errcode = 0) Then
If (logging) Then 'mit Protokollierung
If (check_textfile(logrefnum)) Then
logrefnum.WriteLine ("--- " & Now() & " ---" & crlf & outputfilename_short & ":" & crlf & strOutput)
If (gBAbort) Then
logrefnum.WriteLine (errtext(33)) ' Abbruch durch den Benutzer
End if
End If
End If
Else
ok = false
End If
Else
'errdetails = outputfileverz & outputfilename_short wurde schon in open_outputfile erstellt
ok = False
End If
End If
Line 286 is:
refnum.WriteLine (strOutput)
There are of course two other functions involved (open_outputfile/check_textfile) but they only return a document reference and check if it is a valid reference respectively.
Now I tried to reproduce the error and there is a problem: No matter what I do I don't get this error. I've tried empty references, empty strings, wrote all kind of variable types but I always get other errors.
Can anybody tell me how or why this happens?
I am having an issue with clicking on an OK button in a confirming dialog. This is what I have used but it isn't activating the OK nor is it getting the message property from the dialog. Any ideas as to what is wrong OR better yet, do you have any code that clicks on OK in a confirm dialog?
var confirmHandler = new ConfirmDialogHandler();
using (new UseDialogOnce(newIee.DialogWatcher, confirmHandler))
{
//Click EXIT - CT__Exit
Regex ex = new Regex("CT__Exit");
newIee.Image(Find.ById(ex)).ClickNoWait();
string temp = confirmHandler.Message;
confirmHandler.WaitUntilExists();
Assert.AreEqual(
"Warning! Policy Number or Transaction Type was changed."
+ " Are you sure you want to exit the case?",
confirmHandler.Message);
confirmHandler.OKButton.Click();
}
The script is failing here...confirmHandler.WaitUntilExists();
Is it possible to get the line number, where the script threw an error?
Example:
try
set a to "abc" + "123"
on error line number num
display dialog "Error on line number " & num
end try
i don't think so try statements look like this
try
set a to "abc" + "123"
on error errMsg
display dialog "ERROR: " & errMsg
end try
but you could look at script debugger which will show you what line your error occurred on
another alternative is to get textmate which goes for $52 when it errors it gives you the line number and is also useful for writing code in many languages
Actually the on error syntax include the error number also (but no line number):
try
set a to "abc" + "123"
on error errorMessage number errorNumber
log ("errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try
You can use semaphores to mark your progress:
try
... your code here ...
set lineNumber to "17"
... more code here
set lineNumber to "18"
... more code here
on error errorMessage number errorNumber
log ("(line #" & lineNumber & ") errorMessage: " & errorMessage & ", errorNumber: " & errorNumber)
end try
And I'll 2nd mcgrailm's recommendation for Script Debugger!
Satimage's Smile is of great help when it comes to debugging an applescript.
And it's free.
Plus it's French (hehe).
Definitely a great tool !
Late to the party here, but in respect to Script Debugger, here is a perhaps useful response from Mark Alldritt:
Yes, turn on Break On Exceptions. This cause the debugger to break at the point where an exception is thrown. The debugger also shows the sate of all known variable at the time the exception is thrown. You can then step into the 'on error' block.
Cheers
-Mark
On 2013-01-24, at 8:43 AM, Dan wrote:
When a script throws an error in a Try block, is there any reasonable way to display the line where the error occurred?