Solved

CALLING A  CMD_CLICK() SUB FROM  ANOTHER SUB

Posted on 2004-09-01
5
759 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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 post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

778 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