Computer Science Canada

Disabling Procedure

Author:  vg19 [ Tue Apr 27, 2004 4:48 pm ]
Post subject:  Disabling Procedure

Hi,

I am doing a vb program in which I want to disable a produre. Basically I have a Call statement. Then I have an if statement in the proceudre. What I want to do is if the If statement inside the procedure has been run once, it should disable and never be run again. I am not sure if this can be done.

Please help

Author:  Tony [ Tue Apr 27, 2004 5:00 pm ]
Post subject: 

sounds like a bad programming practice... but... if you must...
code:

sub myProcedure(flag as boolean)

if flag then
end '// should exit the procedure. Not sure on syntax.
end if

print "flag was false, procedure is running

end sub

Author:  Brightguy [ Tue Apr 27, 2004 8:22 pm ]
Post subject:  Re: Disabling Procedure

code:
Private Sub Proc()
    Static blnDisabled As Boolean
    If blnDisabled = True Then
        Exit Sub
    End If
    If <Conditions> Then
        <Statements>
        blnDisabled = True
    End If
End Sub

Once the code in the If statement has been run, the procedure will be "disabled". You can move blnDisabled = True outside of the If statement to always disable the procedure regardless of the conditions, if that's what you wanted.

Author:  McKenzie [ Wed Apr 28, 2004 10:19 am ]
Post subject: 

^ good code.
If you are looking to turn off the button that is calling the procedure use:
code:
btnWhatever.Enabled = False

at the end of the sub


: