Solved

CALLING A  CMD_CLICK() SUB FROM  ANOTHER SUB

Posted on 2004-09-01
5
762 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
Starting up a Project

688 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