Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have some code in a command button which I would like to call from a sub, is this possible?

 

If so what do I put in the arguments?

 

Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

 

Thnx

My website
Posted

Just so I understand, you have code in the cmdNext, that you would also like to use from somewhere else?

 

I would make another sub

 

Private sub sharedsubwhatever(intVariable as int) ' only if you need to pass some variable though

'code

end sub

 

then call this sub in the cmdnext and from the other sub that needs to use the same code

 

Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click

sharedsubwhatever(1)

end sub

 

private sub subthatneedssamecode

sharedsubwhatever(1)

end sub

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

hog,

 

you can call your cmdNext_click eventusing the following

 

cmdNext_click(sender,e)

 

BUT this is considered lazy programming. The solution provided by techmanbd is the cleaner way of programming.

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...