Solved

CALLING A  CMD_CLICK() SUB FROM  ANOTHER SUB

Posted on 2004-09-01
5
760 Views
Last Modified: 2008-03-17
I have a  CmdName_Click()  sub, wich contains same functions wich are
handled in this sub.  I do not want to copy these lines to another sub where
this is needed also. Just trying to call this  CmdName  from this other sub.
How to perform such a call from this second sub.
Regards Jack
0
Comment
Question by:BIAPRO
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:zmorvik
ID: 11952913

In VB6
Just call the CmdName_Click

Private Sub Command1_Click()
     MsgBox "Hello World!"
End Sub

Private Sub Command2_Click()
      'Call Command Button 1 Click
      Command1_Click
End Sub

Could also use Call Command1_Click

In VB.NET:
Refer to the following:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21050738.html


0
 
LVL 22

Expert Comment

by:cookre
ID: 11953197
The 'proper' thing to do is to move the code to be executed by both into its own subroutine and call that subroutine from the two places.
0
 
LVL 4

Expert Comment

by:zmorvik
ID: 11953277
I agree with cookre.  

A function, not another subroutine, that can be called from the two subroutines is what I think would be 'proper'.  

Do you agree cookre?
0
 
LVL 22

Accepted Solution

by:
cookre earned 125 total points
ID: 11954011
Whether function or subroutine depends on whether or not a return value is provided, but the common code should be in its own routine.

0
 
LVL 3

Expert Comment

by:aravindtj
ID: 11954950
Hi,
 why not you put public in the calling methed, ie, which method you want to call?
 You can call that method by putting formname.public method.

If you want it like a template, put it in a module and pass the control objet to that. In the module method, get the proper objet type and manipulate.

 Hope you get the idea.
all the best.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 104
Query Syntax 17 43
Object Oriented Programming, C#, referencing, scoping. 13 69
how i declare an array which contains email address corresponding to names. 2 43
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about a problem I had getting the GPS LocationListener working.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question