Solved

CALLING A  CMD_CLICK() SUB FROM  ANOTHER SUB

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now