44 lines
1.0 KiB
Plaintext
44 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The `GoSub` statement in VB6 is an unstructured control flow statement. It can lead to complex and difficult-to-maintain code, as well as potential stack overflow errors due to improper return handling.
|
|
|
|
Modern programming practices recommend using proper subroutine or function calls instead, which provide better readability, maintainability, and error handling.
|
|
|
|
== How to fix it
|
|
|
|
Replace `GoSub` statements with proper subroutine or function calls.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,vb6,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
Sub ExampleProcedure()
|
|
GoSub SubRoutine
|
|
Exit Sub
|
|
|
|
SubRoutine:
|
|
' ...
|
|
Return
|
|
End Sub
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,vb6,diff-id=1,diff-type=compliant]
|
|
----
|
|
Sub ExampleProcedure()
|
|
Call SubRoutine
|
|
End Sub
|
|
|
|
Sub SubRoutine()
|
|
' ...
|
|
End Sub
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Microsoft Learn - https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/gosubreturn-statement[GoSub...Return statement]
|