Solved

CALLING A  CMD_CLICK() SUB FROM  ANOTHER SUB

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 115
allStar challenge 1 52
How does Google get such fast response times? 5 155
Adding Namespace to the second node of the xml 16 65
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
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.
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…

863 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

21 Experts available now in Live!

Get 1:1 Help Now