Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
RSvebeck
Specialist
Specialist

Check if Sub is existing

Is it possible to know in the script if a sub is existing?

Svebeck Consulting AB
1 Solution

Accepted Solutions
swuehl
MVP
MVP

Sorry for a late answer.

If you can't check if a Sub exists in the previous script code, why not revert back to the old include guards?

include guard - Wikipedia

Alternatively, define a unique variable in your include files and use a conditional to only include the file if the variable is not set.

View solution in original post

6 Replies
RSvebeck
Specialist
Specialist
Author

.... except by "trying to use it, with errorlevel=0, and dealing with the error...." 🙂

Svebeck Consulting AB
swuehl
MVP
MVP

Or search / read through the code prior the call...?

Not sure If I understand your request, what would be your use case?

RSvebeck
Specialist
Specialist
Author

I'm using a big library of "include files" where I keep many subs that are considered to be useful for many different scripts, and the scripts are themselves also includefiles.

For instance, I have a sub called "sub_send_mail()". This sub is then used by some other subs that are then used in many different applications.

Basically I would like to make sure Before including a sub in my script, that the sub is not already included by some other include file.

Something like this: "If not exists Sub('sub_send_mail') then (Include=..\scripts\sub_send_mail.qvs)"

/Robert

Svebeck Consulting AB
RSvebeck
Specialist
Specialist
Author

‌Fir reference, the answer is no. No way to check that.

Svebeck Consulting AB
swuehl
MVP
MVP

Sorry for a late answer.

If you can't check if a Sub exists in the previous script code, why not revert back to the old include guards?

include guard - Wikipedia

Alternatively, define a unique variable in your include files and use a conditional to only include the file if the variable is not set.

RSvebeck
Specialist
Specialist
Author

‌Its just a great feeling when the solution is there and you just don't see it unless you get somone to make you look to the right direction!

Thanks Stefan!

The idea to make variable named as the sub will be a great way to solve it!

regards

Robert

Svebeck Consulting AB