0

I'm writing a function to create a new folder and return the path to that folder.

If the function finds that the folder already exists the script should be exited to avoid any problems with the existing folder and documents.

Given that the function is declared as

Function New_Folder (ByVal Name As String) As String

what should it return if it "fails" to indicate an error? Just "1" in the string and the receiving sub will have to just deal with it? Is there a conventional way to handle this?

Thanks! (Apologies for asking a question that is likely answered thoroughly elsewhere, haven't been able to find it)

Community
  • 1
  • 1
Hugh_Kelley
  • 988
  • 1
  • 9
  • 23

1 Answers1

2

If you are certain you want to return a value to indicate failure as opposed to raising an error and handling it in the calling function, then you probably should return the null string, vbNullString.

A convenient way to do that is to not assign anything to New_Folder before exiting. It will be vbNullString by default.

You should consider raising an error though.

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • thanks, hadn't considered that because I wasn't aware of it. Haven't done much beyond HRESULT style success: return 0, failure: return some positive integer associated with the specific error. vbNullString is fine for now, it's at least better than returning "1" like i was considering. – Hugh_Kelley Jun 15 '18 at 19:00