How to pass a control optionally

E

eagle

How can I pass a control to another procedure as an option?

I tried:
Call DoStuff(lbl)

Private Sub DoStuff(Optional lnkbtn = nothing)

if lnkbtn <> nothing then lnkbtn.visible = true

end sub


and I get an error saying Operator is not valid for type LinkButton and
Nothing
 
S

Siva M

Hi,

Try DoStuff(Optional lnkbtn As Control = Nothing)

How can I pass a control to another procedure as an option?

I tried:
Call DoStuff(lbl)

Private Sub DoStuff(Optional lnkbtn = nothing)

if lnkbtn <> nothing then lnkbtn.visible = true

end sub


and I get an error saying Operator is not valid for type LinkButton and
Nothing
 
M

Marina

1. Turn Option Strict On. Declare types for all your objects.
2. If Not IsNothing(lnkbtn) Then lnkbtn.Visible = True
 
K

Karl Seguin

Or, use overloading

public sub DoStuff()
DoStuff(nothing)
end sub
public sub DoStuff(byval control as Control)
if not control is nothing then
control.Visible = true
end if
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top