Page 1 of 1

Verifying a stock transfer and and activation

PostPosted: Wed Dec 16, 2015 2:38 pm
by indikad
The jiwa 7 Stock transfer object has a Save method that is a sub rather than the function that was in 6513 ( SaveRecord)
in 6513 I was able to verify if the stock transfer was created by checking the return value of the SaveRecord method.
How do I do this in Jiwa7 object ?

similarly I need to verify the Activation was successfull or not too (ActivateRecord method )


related thread -
viewtopic.php?f=27&t=491&p=1678#p1678

Re: Verifying a stock transfer and and activation

PostPosted: Wed Dec 16, 2015 2:55 pm
by Scott.Pearce
Wrap your call to Save() in a try catch block thus:

Code: Select all
Try
  myStockTransferObject.Save
Catch ex as Exception
  msgbox(ex.Message) 'Or you could log to the eventlog, a file, do nothing, whatever you like.
End Try


The Catch block is only entered if there is a problem inside the myStockTransferObject.Save method. Our methods will always Throw() if there is a problem. This is a fundamental construct in .Net, so I recommend you read up here.

Re: Verifying a stock transfer and and activation

PostPosted: Wed Dec 16, 2015 3:26 pm
by indikad
thanks Scott. I already use try - Catch.
I was just wondering if there was a possibly of getting a return value thats all.

all good.

Re: Verifying a stock transfer and and activation  Topic is solved

PostPosted: Wed Dec 16, 2015 5:09 pm
by Mike.Sheen
indikad wrote:I was just wondering if there was a possibly of getting a return value thats all.


No - subs don't return a value only functions can.

The old way might have had a return code of an integer which was an enumerated type - 0 = failure, -1 = success, 1 = cancelled.

The new pattern is to throw an exception on error, and throw an exception of type clientcancelled on cancellation.

So, you can emulate the old behaviour in your invocation to the sub:

Code: Select all
Dim returnValue as Integer = -1 ' Default to success
Try
    myStockTransferObject.Save
Catch cancelledEx As JiwaApplication.Exceptions.ClientCancelledException
    returnValue = 1
Catch ex As System.Exception
    returnValue = 0
End Try


Personally, I wouldn't do that.