Probably I found a bug in VBScript

Probably I found a bug in VBScript

jtm2020hyo
Collaborator Collaborator
1,264 Views
3 Replies
Message 1 of 4

Probably I found a bug in VBScript

jtm2020hyo
Collaborator
Collaborator

Hello everyone.

 

Probably I found a bug with the VBScript. I was creating and experimenting a lot with the VBScript function if-then-elseif-else statement and I found something that before saving my drawing was working, but know that I was checking again simply stop working.

 

 

imagen.pngimagen.png

 

I was linking multiple functions to the function name "NAME_BY_OBJECT" which generate a different name per each different object. In images 1 and 2, everything is correct...

 

... but something weird happens with I add the object type "Hanger":

 

imagen.pngimagen.png

 

... again everything works correct, but just with hangers, but I was checking the cable trays and cable trays fitting this happens:

 

imagen.pngimagen.png

 

 

I do not what happens here.

 

1) am I doing something bad? if yes, how can I fix this?

2) if not, What Is wrong, and what alternatives exist?

 

PD: attached files

 

 

If "[ObjectType]" = "Cable Tray" Then
	RESULT = "[NAME_CABLE_TRAY]"

ElseIf "[ObjectType]" = "Cable Tray Fitting" Then
	RESULT = "[NAME_CABLE_TRAY_FITTING]"

ElseIf "[ObjectType]" = "Hanger" Then
	RESULT = "[NAME_HANGER]"

Else
	RESULT = "NA"

End If

 

 

0 Likes
Accepted solutions (1)
1,265 Views
3 Replies
Replies (3)
Message 2 of 4

vince.krueger
Advocate
Advocate
Accepted solution

Your code looks fine, but If..elseIf is not the best method here (and apparently does not work in your situation).

 

I prefer to use the Select..Case statements in these situations.

Message 3 of 4

jtm2020hyo
Collaborator
Collaborator

exist documentation about why elseif leave the error in this situation?

0 Likes
Message 4 of 4

vince.krueger
Advocate
Advocate

No existing document that I found other than Microsoft also recommends the Select...Case instead for VBA applications.  May be a know issue that is not worth addressing or just something with the instance you have.  I have seen some rather weird activities in the past (like setting a variable to a constant crashing VBA with something becomes corrupt).  In most cases rebooting the computer solves the problem, but others are not so easily solved.