Check for Sub existance

Scubaticus

Active Member
Licensed User
Is there a way to find out if a Sub exists.

I know I can use an errorlabel to catch undefined callSubs, but I'm looking for a clean way to find out the existence of a sub.

One problem using the errorlabel cause the program to loop, but this is probably because the errorlabel itself is in the If stucture:
Sub doCalSubs

ErrorLabel(InValidSub)

For ii = 1 To 2
CallSub ("Sub_" & ii)
InValidSub:
Next


End Sub

Sub Sub_1
End Sub

So a separate question is, what is happening with my vars when an error jumps in?


Scub.
 
Last edited:

Scubaticus

Active Member
Licensed User
I assume that you know the names of all the subs.
You can add these names to an ArrayList and use ArrayList.IndexOf to check if the sub exists.

Before the callSub I used a Select/Case......
Now when I ad a sub, or remove it I also have to keep track of the array values.

It would be nice if there was some kind of "if exist" (sub, control, etc.)

Scub
 

Cableguy

Expert
Licensed User
Longtime User
Still I agree with Erel.....

I do can see your point, but beeing a sub a must know thing in your app, it's easyer to create an array and update it...

It would be nice to have a "special" array with all the subs names automatically updated when project was saved...
 

Scubaticus

Active Member
Licensed User
Still I agree with Erel.....
Well, yes and no. Of course, it's a good thing to know your subs. But I work with "objects" and one of it's properties is used as a special sub-call. But it does not need to exist.

Life would become easier (just like the function_exists in PHP for example). I'm just missing the check of existence. The controls for example. Do you put all your controls in array? I don't, but trying to set a control, because you use a template for example, which does not exist causes an error to rise. And yes to catch those errors errorlabel could be used, but I think the errorlabel thing is not what it should be. I'm not interested if an error somewhere in my sub occurs, but do if it's on a specific statement. Now I have to define a whole new sub just to catch these kind of errors......


Scub
 
Top