Author Topic: How to return error messages in the cell?  (Read 555 times)

iamstephenwang

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
How to return error messages in the cell?
« on: May 28, 2015, 04:01:05 PM »
Hi Tony,

I am trying to achieve something like this but not sure what the best way is. Pseudo code below:

@xl_func("float a, float b, date c: bool")
def myFunc(a, b, c):
    if someCondition:
       throwAnException (so I can see it in the log)
       Return an error message as string and display it in the cell (so the user knows something goes wrong)
    else:
       return func2(a,b,c) # which returns True or False

The return type in my function argument is bool but I would like to return a string under some conditions (say some inputs are invalid/blank, etc.).

I think changing the return type from bool to var might work, but I am worried about the potential performance impact...

Any advice?

Thank you very much.

Stephen


Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 584
  • Karma: +14/-1
    • View Profile
Re: How to return error messages in the cell?
« Reply #1 on: May 28, 2015, 04:10:01 PM »
Hi Stephen,

changing the return type to var is the right thing to do. The performance impact will be negligible so I wouldn't worry about that.

Best regards,
Tony

iamstephenwang

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: How to return error messages in the cell?
« Reply #2 on: May 30, 2015, 02:52:39 AM »
Understood. Thanks Tony.